FeaturesCreatorActor { public void createFeaturesByMessage(final CreateFeaturesWrapper wrapper) throws FeatureCreationException { try { Map<String, IFeature> features = new HashMap<>(); List<IObject> repositories = wrapper.getRepositoriesDescription(); List<IObject> repositoryStorage = IOC.resolve(Keys.getOrAdd("feature-repositories")); if (null != repositories) { for (IObject repository : repositories) { repositoryStorage.add(repository); } } List<IObject> featuresFromJson = wrapper.getFeaturesDescription(); if (null != featuresFromJson) { for (IObject feature : featuresFromJson) { String name = (String) feature.getValue(this.nameFN); if (null != feature.getValue(this.groupFN)) { features.put(name, new Feature( name, (String) feature.getValue(this.groupFN), (String) feature.getValue(this.versionFN), new Path(wrapper.getFeatureDirectory()) ) ); } else { features.put(name, new Feature( name, null, (IPath) feature.getValue(this.featureLocationFN) ) ); } } } wrapper.setFeatures(features.values()); } catch (ResolutionException | ChangeValueException | ReadValueException | InvalidArgumentException e) { throw new FeatureCreationException(e); } } FeaturesCreatorActor(); void createMessageByFile(final CreateMessageWrapper wrapper); void createFeaturesByMessage(final CreateFeaturesWrapper wrapper);  }
@Test public void checkCreationFeatureByMessageMethodBasedOnJsonFile() throws Exception { List<IObject> repositoryStorage = new ArrayList<>(); IOC.register(Keys.getOrAdd("feature-repositories"), new SingletonStrategy(repositoryStorage)); FeaturesCreatorActor actor = new FeaturesCreatorActor(); CreateFeaturesWrapper wrapper = mock(CreateFeaturesWrapper.class); IObject json = new DSObject( "{\n" + " \"repositories\": [\n" + " {\n" + " \"repositoryId\": \"repository1\",\n" + " \"type\": \"default\",\n" + " \"url\": \"info.smart_tools.smartactors\"\n" + " }\n" + " ],\n" + " \"features\": [\n" + " {\n" + " \"name\": \"feature1\",\n" + " \"group\": \"info.smart_tools.smartactors\",\n" + " \"version\": \"0.0.0\"\n" + " }\n" + " ]\n" + "}" ); when(wrapper.getRepositoriesDescription()).thenReturn( (List<IObject>) json.getValue(new FieldName("repositories")) ); when(wrapper.getFeaturesDescription()).thenReturn( (List<IObject>) json.getValue(new FieldName("features")) ); Collection<IFeature> features = new HashSet<>(); doAnswer(invocationOnMock -> { try { ((Collection<IFeature>)invocationOnMock.getArguments()[0]).forEach((f) -> { features.add(f); }); } catch (Throwable e) { throw new RuntimeException(e); } return null; }).when(wrapper).setFeatures(any()); actor.createFeaturesByMessage(wrapper); assertEquals(features.size(), 1); assertEquals(((IFeature) features.toArray()[0]).getName(), "feature1"); assertEquals(((IFeature) features.toArray()[0]).getGroupId(), "info.smart_tools.smartactors"); assertEquals(((IFeature) features.toArray()[0]).getVersion(), "0.0.0"); }
@Test public void checkCreationFeatureByMessageMethodBasedOnZipFile() throws Exception { List<IObject> repositoryStorage = new ArrayList<>(); IOC.register(Keys.getOrAdd("feature-repositories"), new SingletonStrategy(repositoryStorage)); FeaturesCreatorActor actor = new FeaturesCreatorActor(); CreateFeaturesWrapper wrapper = mock(CreateFeaturesWrapper.class); IObject json = new DSObject( "{\"features\": [{\"name\":\"test-feature\",\"version\":null,\"group\":null}]}" ); ((List<IObject>) json.getValue(new FieldName("features"))).get(0).setValue(new FieldName("featureLocation"), new Path("target/test-classes/test-feature-0.0.1-archive.zip")); when(wrapper.getFeaturesDescription()).thenReturn( (List<IObject>) json.getValue(new FieldName("features")) ); Collection<IFeature> features = new HashSet<>(); doAnswer(invocationOnMock -> { try { ((Collection<IFeature>)invocationOnMock.getArguments()[0]).forEach((f) -> { features.add(f); }); } catch (Throwable e) { throw new RuntimeException(e); } return null; }).when(wrapper).setFeatures(any()); actor.createFeaturesByMessage(wrapper); assertEquals(features.size(), 1); assertEquals(((IFeature) features.toArray()[0]).getName(), "test-feature"); assertEquals(((IFeature) features.toArray()[0]).getGroupId(), null); assertEquals(((IFeature) features.toArray()[0]).getVersion(), null); assertEquals(((IFeature) features.toArray()[0]).getFeatureLocation(), new Path("target/test-classes/test-feature-0.0.1-archive.zip")); }