InstanceStoreV1(IdentifierSourceSet identifierSources, String name, InstanceDomain instanceDomain) { super(identifierSources.instanceSource(name)); this.instanceDomain = instanceDomain; }
InstanceStoreV2(IdentifierSourceSet identifierSources, String name, InstanceDomain instanceDomain, PcpStringStore stringStore) { super(identifierSources.instanceSource(name)); this.instanceDomain = instanceDomain; this.stringStore = stringStore; }
public IdentifierSource getInstanceSource(String instanceDomain) { IdentifierSource found = instanceSources.get(instanceDomain); return (found == null) ? fallbacks.instanceSource(instanceDomain) : found; } }
if (currentDomain != null) { instanceSources.put(currentDomain, new FixedValueIdentifierSource( currentInstanceAllocations, fallbacks.instanceSource(currentDomain))); currentInstanceAllocations, fallbacks.instanceSource(currentDomain)));
private void assertInstanceResultMatches(List<String> input) { IdentifierSourceSet sources = new StringParsingIdentifierSourceSet(input, Collections .<String> emptyList(), FALLBACK_SOURCES); assertEquals(INSTANCE_ID, sources.instanceSource(DOMAIN_NAME).calculateId(INSTANCE_NAME, Collections.<Integer> emptySet())); } }
@Test public void instanceStoreShouldCreateANewInstance() { IdentifierSourceSet identifierSourceSet = mock(IdentifierSourceSet.class); IdentifierSource identifierSource = mock(IdentifierSource.class); InstanceDomain instanceDomain = mock(InstanceDomain.class); PcpStringStore stringStore = mock(PcpStringStore.class); PcpString pcpString = mock(PcpString.class); when(identifierSourceSet.instanceSource(INSTANCE_NAME)).thenReturn(identifierSource); when(identifierSource.calculateId(eq(INSTANCE_NAME), ArgumentMatchers.<Integer>anySet())).thenReturn(123); when(stringStore.createPcpString(INSTANCE_NAME)).thenReturn(pcpString); InstanceV2.InstanceStoreV2 instanceStore = new InstanceV2.InstanceStoreV2(identifierSourceSet, INSTANCE_NAME, instanceDomain, stringStore); Instance actual = instanceStore.byName(INSTANCE_NAME); InstanceV2 expected = new InstanceV2(instanceDomain, INSTANCE_NAME, 123, pcpString); assertReflectionEquals(expected, actual); }
@Test public void instanceValuesShouldBeParsedFromReader() { assertEquals(INSTANCE_ID, buildReaderSet(tempReader(INSTANCE_FILE), null).instanceSource( DOMAIN_NAME).calculateId(INSTANCE_NAME, NO_IDS)); }
@Test public void instanceValuesShouldBeParsedFromFile() { assertEquals(INSTANCE_ID, buildFileSet(tempFile(INSTANCE_FILE), null).instanceSource( DOMAIN_NAME).calculateId(INSTANCE_NAME, NO_IDS)); }
@Test public void instanceValuesShouldBeParsedFromStream() { assertEquals(INSTANCE_ID, buildStreamSet(tempStream(INSTANCE_FILE), null).instanceSource( DOMAIN_NAME).calculateId(INSTANCE_NAME, NO_IDS)); }