BlueprintFactory { @SuppressWarnings("unchecked") public Blueprint createBlueprint(Map<String, Object> properties, SecurityConfiguration securityConfiguration) throws NoSuchStackException { String name = String.valueOf(properties.get(BLUEPRINT_NAME_PROPERTY_ID)); if (name.equals("null") || name.isEmpty()) { throw new IllegalArgumentException("Blueprint name must be provided"); } Stack stack = createStack(properties); Collection<HostGroup> hostGroups = processHostGroups(name, stack, properties); Configuration configuration = configFactory.getConfiguration((Collection<Map<String, String>>) properties.get(CONFIGURATION_PROPERTY_ID)); Setting setting = SettingFactory.getSetting((Collection<Map<String, Object>>) properties.get(SETTINGS_PROPERTY_ID)); return new BlueprintImpl(name, hostGroups, stack, configuration, securityConfiguration, setting); } BlueprintFactory(); protected  BlueprintFactory(StackFactory stackFactory); Blueprint getBlueprint(String blueprintName); @SuppressWarnings("unchecked") Blueprint createBlueprint(Map<String, Object> properties, SecurityConfiguration securityConfiguration); @Inject static void init(BlueprintDAO dao);  }
@Test public void testCreateBlueprint() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); replay(stack, dao, entity, configEntity); Blueprint blueprint = testFactory.createBlueprint(props, null); assertEquals(BLUEPRINT_NAME, blueprint.getName()); assertSame(stack, blueprint.getStack()); assertEquals(2, blueprint.getHostGroups().size()); Map<String, HostGroup> hostGroups = blueprint.getHostGroups(); HostGroup group1 = hostGroups.get("group1"); assertEquals("group1", group1.getName()); assertEquals("1", group1.getCardinality()); Collection<String> components = group1.getComponentNames(); assertEquals(2, components.size()); assertTrue(components.contains("component1")); assertTrue(components.contains("component2")); Collection<String> services = group1.getServices(); assertEquals(2, services.size()); assertTrue(services.contains("test-service1")); assertTrue(services.contains("test-service2")); assertTrue(group1.containsMasterComponent()); Configuration configuration = group1.getConfiguration(); assertTrue(configuration.getProperties().isEmpty()); assertTrue(configuration.getAttributes().isEmpty()); HostGroup group2 = hostGroups.get("group2"); assertEquals("group2", group2.getName()); assertEquals("2", group2.getCardinality()); components = group2.getComponentNames(); assertEquals(1, components.size()); assertTrue(components.contains("component1")); services = group2.getServices(); assertEquals(1, services.size()); assertTrue(services.contains("test-service1")); assertTrue(group2.containsMasterComponent()); configuration = group2.getConfiguration(); assertTrue(configuration.getProperties().isEmpty()); assertTrue(configuration.getAttributes().isEmpty()); verify(dao, entity, configEntity); }
@Test(expected=IllegalArgumentException.class) public void testCreate_NoBlueprintName() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); props.remove(BlueprintResourceProvider.BLUEPRINT_NAME_PROPERTY_ID); replay(stack, dao, entity, configEntity); testFactory.createBlueprint(props, null); }
@Test(expected=IllegalArgumentException.class) public void testCreate_NoHostGroups() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); ((Set<Map<String, Object>>) props.get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).clear(); replay(stack, dao, entity, configEntity); testFactory.createBlueprint(props, null); }
@Test(expected=IllegalArgumentException.class) public void testCreate_MissingHostGroupName() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); ((Set<Map<String, Object>>) props.get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)).iterator().next().remove("name"); replay(stack, dao, entity, configEntity); testFactory.createBlueprint(props, null); }
@Test(expected=IllegalArgumentException.class) public void testCreate_HostGroupWithNoComponents() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); ((Set<Map<String, Object>>) props.get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)). iterator().next().remove(BlueprintResourceProvider.COMPONENT_PROPERTY_ID); replay(stack, dao, entity, configEntity); testFactory.createBlueprint(props, null); }
@Test(expected=IllegalArgumentException.class) public void testCreate_HostGroupWithInvalidComponent() throws Exception { Map<String, Object> props = BlueprintResourceProviderTest.getBlueprintTestProperties().iterator().next(); ((Set<Map<String, Object>>) ((Set<Map<String, Object>>) props.get(BlueprintResourceProvider.HOST_GROUP_PROPERTY_ID)). iterator().next().get(BlueprintResourceProvider.COMPONENT_PROPERTY_ID)).iterator().next().put("name", "INVALID_COMPONENT"); replay(stack, dao, entity, configEntity); testFactory.createBlueprint(props, null); }