FeaturesCreatorActor { public void createMessageByFile(final CreateMessageWrapper wrapper) throws FeatureCreationException { try { File file = new File(wrapper.getObservedDirectory() + File.separator + wrapper.getFileName()); if (file.exists() && !file.isDirectory()) { if (file.getName().endsWith(".zip")) { wrapper.setJsonFeaturesDescription(createJsonFeatureDescriptionByZip(file, wrapper.getObservedDirectory())); wrapper.setJsonRepositoriesDescription(new ArrayList<IObject>()); } if (file.getName().endsWith(".json")) { wrapper.setJsonFeaturesDescription(getDescription(file, this.featuresFN)); wrapper.setJsonRepositoriesDescription(getDescription(file, this.repositoriesFN)); } } } catch (ReadValueException | ChangeValueException e) { throw new FeatureCreationException("Could not create features by given file.", e); } } FeaturesCreatorActor(); void createMessageByFile(final CreateMessageWrapper wrapper); void createFeaturesByMessage(final CreateFeaturesWrapper wrapper);  }
@Test public void checkCreateMessageByZipFileMethod() throws Exception { FeaturesCreatorActor actor = new FeaturesCreatorActor(); CreateMessageWrapper wrapper = mock(CreateMessageWrapper.class); when(wrapper.getFileName()).thenReturn("test-feature-0.0.1-archive.zip"); when(wrapper.getObservedDirectory()).thenReturn("target/test-classes/"); doAnswer(invocationOnMock -> { try { IObject featureDescription = (IObject) ((List) invocationOnMock.getArguments()[0]).get(0); assertEquals(featureDescription.getValue(new FieldName("name")), "test-feature"); assertEquals( featureDescription.getValue(new FieldName("featureLocation")), new Path("target/test-classes/test-feature-0.0.1-archive.zip") ); } catch (Throwable e) { throw new RuntimeException(e); } return null; }).when(wrapper).setJsonFeaturesDescription(any()); actor.createMessageByFile(wrapper); }
@Test public void checkCreateMessageByJsonFileMethod() throws Exception { FeaturesCreatorActor actor = new FeaturesCreatorActor(); CreateMessageWrapper wrapper = mock(CreateMessageWrapper.class); when(wrapper.getFileName()).thenReturn("features.json"); when(wrapper.getObservedDirectory()).thenReturn("target/test-classes/"); doAnswer(invocationOnMock -> { try { IObject featureDescription = (IObject) ((List) invocationOnMock.getArguments()[0]).get(0); assertEquals(featureDescription.getValue(new FieldName("name")), "feature1"); assertEquals(featureDescription.getValue(new FieldName("version")), "0.0.0"); assertEquals(featureDescription.getValue(new FieldName("group")), "info.smart_tools.smartactors"); } catch (Throwable e) { throw new RuntimeException(e); } return null; }).when(wrapper).setJsonFeaturesDescription(any()); doAnswer(invocationOnMock -> { try { IObject featureDescription = (IObject) ((List) invocationOnMock.getArguments()[0]).get(0); assertEquals(featureDescription.getValue(new FieldName("repositoryId")), "repository1"); assertEquals(featureDescription.getValue(new FieldName("type")), "default"); assertEquals(featureDescription.getValue(new FieldName("url")), "info.smart_tools.smartactors"); } catch (Throwable e) { throw new RuntimeException(e); } return null; }).when(wrapper).setJsonRepositoriesDescription(any()); actor.createMessageByFile(wrapper); actor.createMessageByFile(wrapper); }