Search in sources :

Example 16 with DataStore

use of io.fabric8.api.DataStore in project fabric8 by jboss-fuse.

the class ContainerImplTest method testGetContainerProfileOverlay.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testGetContainerProfileOverlay() throws Exception {
    String v = "1.0";
    String defaultProfile = "default";
    String camelProfile = "feature-camel";
    String cxfProfile = "feature-cxf";
    // new VersionImpl(v, fabricService);
    Version version = null;
    List<String> profiles = Arrays.asList(camelProfile, cxfProfile);
    Map<String, String> defaultAttributes = new HashMap<String, String>();
    Map<String, String> camelAttributes = new HashMap<String, String>();
    Map<String, String> cxfAttributes = new HashMap<String, String>();
    Map<String, byte[]> defaultFiles = new HashMap<String, byte[]>();
    Map<String, byte[]> camelFiles = new HashMap<String, byte[]>();
    Map<String, byte[]> cxfFiles = new HashMap<String, byte[]>();
    Map<String, Map<String, String>> defaultPids = new HashMap<String, Map<String, String>>();
    Map<String, Map<String, String>> camelPids = new HashMap<String, Map<String, String>>();
    Map<String, Map<String, String>> cxfPids = new HashMap<String, Map<String, String>>();
    camelAttributes.put("attribute." + Profile.PARENTS, "default");
    cxfAttributes.put("attribute." + Profile.PARENTS, "feature-camel");
    defaultFiles.put("test1.properties", "key=fromDefault".getBytes());
    camelFiles.put("test1.properties", "key=fromCamel".getBytes());
    cxfFiles.put("test2.properties", "key=fromCxf".getBytes());
    expect(fabricService.getEnvironment()).andReturn("").anyTimes();
    expect(profileService.getRequiredVersion(eq(v))).andReturn(version).anyTimes();
    // Define Attributes
    // expect(profileRegistry.getProfileAttributes(eq(v), eq(defaultProfile))).andReturn(defaultAttributes).anyTimes();
    // expect(profileRegistry.getProfileAttributes(eq(v), eq(camelProfile))).andReturn(camelAttributes).anyTimes();
    // expect(profileRegistry.getProfileAttributes(eq(v), eq(cxfProfile))).andReturn(cxfAttributes).anyTimes();
    // Define Files
    // expect(profileRegistry.getFileConfigurations(eq(v), eq(defaultProfile))).andReturn(defaultFiles).anyTimes();
    // expect(profileRegistry.getFileConfigurations(eq(v), eq(camelProfile))).andReturn(camelFiles).anyTimes();
    // expect(profileRegistry.getFileConfigurations(eq(v), eq(cxfProfile))).andReturn(cxfFiles).anyTimes();
    // Define PIDS
    // expect(profileRegistry.getConfigurations(eq(v), eq(defaultProfile))).andReturn(defaultPids).anyTimes();
    // expect(profileRegistry.getConfigurations(eq(v), eq(camelProfile))).andReturn(camelPids).anyTimes();
    // expect(profileRegistry.getConfigurations(eq(v), eq(cxfProfile))).andReturn(cxfPids).anyTimes();
    fabricService.substituteConfigurations((Map<String, Map<String, String>>) anyObject());
    expectLastCall().anyTimes();
    expect(dataStore.getContainerVersion(eq(CONTAINER_ID))).andReturn(v).anyTimes();
    expect(dataStore.getContainerProfiles(eq(CONTAINER_ID))).andReturn(profiles).anyTimes();
    expect(profileRegistry.hasProfile(v, camelProfile)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, cxfProfile)).andReturn(true).anyTimes();
    replay(fabricService);
    replay(dataStore);
    Map<String, Map<String, String>> configs = container.getOverlayProfile().getConfigurations();
    assertNotNull(configs);
    assertEquals(2, configs.size());
    assertNotNull(configs.get("test1"));
    assertEquals(1, configs.get("test1").size());
    assertEquals("fromCamel", configs.get("test1").get("key"));
    assertNotNull(configs.get("test2"));
    assertEquals(1, configs.get("test2").size());
    assertEquals("fromCxf", configs.get("test2").get("key"));
    verify(fabricService);
    verify(dataStore);
}
Also used : Version(io.fabric8.api.Version) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with DataStore

use of io.fabric8.api.DataStore in project fabric8 by jboss-fuse.

the class ContainerImplTest method testContainerProfileWithMissingParents.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testContainerProfileWithMissingParents() throws Exception {
    String v = "1.0";
    String profile1Id = "feature-camel";
    String profile2Id = "feature-cxf";
    String missing = "missing";
    // new VersionImpl(v, fabricService);
    Version version = null;
    List<String> profiles = Arrays.asList(profile1Id, profile2Id, missing);
    expect(profileService.getRequiredVersion(eq(v))).andReturn(version).anyTimes();
    expect(fabricService.getEnvironment()).andReturn("").anyTimes();
    expect(dataStore.getContainerVersion(eq(CONTAINER_ID))).andReturn(v).anyTimes();
    expect(dataStore.getContainerProfiles(eq(CONTAINER_ID))).andReturn(profiles).anyTimes();
    expect(profileRegistry.hasProfile(v, profile1Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, profile2Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, missing)).andReturn(false).anyTimes();
    // expect(profileRegistry.getProfileAttributes(eq(v), EasyMock.<String>anyObject())).andReturn(Maps.<String, String>newHashMap()).anyTimes();
    replay(fabricService);
    replay(dataStore);
    Profile overlay = container.getOverlayProfile();
    List<String> parents = overlay.getParentIds();
    assertEquals(2, parents.size());
    verify(fabricService);
    verify(dataStore);
}
Also used : Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 18 with DataStore

use of io.fabric8.api.DataStore in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method setUp.

@Before
public void setUp() {
    fabricService = createMock(FabricService.class);
    dataStore = createMock(DataStore.class);
    expect(fabricService.getCurrentContainerName()).andReturn("root").anyTimes();
    expect(fabricService.adapt(DataStore.class)).andReturn(dataStore).anyTimes();
    expect(fabricService.getContainer(EasyMock.<String>anyObject())).andStubAnswer(new IAnswer<Container>() {

        @Override
        public Container answer() throws Throwable {
            return new ContainerImpl(null, (String) EasyMock.getCurrentArguments()[0], fabricService);
        }
    });
    expect(dataStore.getContainerAttribute(eq("root"), eq(DataStore.ContainerAttribute.Ip), eq(""), eq(false), eq(true))).andReturn(ip).anyTimes();
    expect(dataStore.getContainerAttribute(eq("root"), eq(DataStore.ContainerAttribute.LocalHostName), eq(""), eq(false), eq(true))).andReturn(localhostname).anyTimes();
    expect(dataStore.getContainerAttribute(eq("root"), eq(DataStore.ContainerAttribute.BindAddress), eq(""), eq(false), eq(true))).andReturn(bindaddress).anyTimes();
    expect(dataStore.getContainerAttribute(eq("root"), eq(DataStore.ContainerAttribute.Resolver), eq(""), eq(false), eq(true))).andReturn(containerResolver).anyTimes();
    replay(fabricService);
    replay(dataStore);
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerImpl(io.fabric8.internal.ContainerImpl) DataStore(io.fabric8.api.DataStore) Before(org.junit.Before)

Example 19 with DataStore

use of io.fabric8.api.DataStore in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveNameContainerAttributes.

@Test
public void testResolveNameContainerAttributes() throws Exception {
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:root/ip"));
    assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:root/localhostname"));
    assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:root/bindaddress"));
    assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:root/resolver"));
    verify(fabricService);
    verify(dataStore);
}
Also used : PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 20 with DataStore

use of io.fabric8.api.DataStore in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveCurrentAttributes.

@Test
public void testResolveCurrentAttributes() throws Exception {
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:ip"));
    assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:localhostname"));
    assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:bindaddress"));
    assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:resolver"));
    verify(fabricService);
    verify(dataStore);
}
Also used : PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 Version (io.fabric8.api.Version)8 Ignore (org.junit.Ignore)7 DataStore (io.fabric8.api.DataStore)6 Profile (io.fabric8.api.Profile)5 Before (org.junit.Before)5 FabricService (io.fabric8.api.FabricService)4 PlaceholderResolver (io.fabric8.api.PlaceholderResolver)4 ContainerImpl (io.fabric8.internal.ContainerImpl)4 File (java.io.File)4 IOException (java.io.IOException)4 DataStoreTemplate (io.fabric8.api.DataStoreTemplate)3 ProfileBuilder (io.fabric8.api.ProfileBuilder)3 RuntimeProperties (io.fabric8.api.RuntimeProperties)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 CuratorFramework (org.apache.curator.framework.CuratorFramework)3 Container (io.fabric8.api.Container)2 FabricException (io.fabric8.api.FabricException)2 GitContext (io.fabric8.api.GitContext)2