UnzipFeatureActor { public void unzip(final UnzipFeatureWrapper wrapper) throws UnzipFeatureException { IFeature feature; try { feature = wrapper.getFeature(); } catch (ReadValueException e) { throw new UnzipFeatureException("Feature should not be null."); } try { if (null == feature.getDependencies() && feature.getFeatureLocation().toString().endsWith(".zip")) { System.out.println("[INFO] Start unzipping feature - '" + feature.getName() + "'."); File f = new File(feature.getFeatureLocation().toString()); File configFile = unzip0(f); updateFeature(configFile, feature); System.out.println("[OK] -------------- Feature '" + feature.getName() + "' has been unzipped successful."); } } catch (Throwable e) { feature.setFailed(true); System.out.println("[FAILED] ---------- Feature '" + feature.getName() + "' unzipping has been aborted with exception:"); System.out.println(e); } } UnzipFeatureActor(); void unzip(final UnzipFeatureWrapper wrapper);  }
@Ignore @Test public void checkUnzipMethod() throws Exception { UnzipFeatureActor actor = new UnzipFeatureActor(); UnzipFeatureWrapper wrapper = mock(UnzipFeatureWrapper.class); IFeature feature = mock(IFeature.class); when(feature.getName()).thenReturn("test-feature"); when(feature.getDependencies()).thenReturn(null); String fileName = "target/test-classes/test-feature-VERSION-archive.zip"; String directory = "target/test-classes/test-feature-VERSION"; when(feature.getFeatureLocation()).thenReturn( new Path(fileName) ); when(wrapper.getFeature()).thenReturn(feature); actor.unzip(wrapper); verify(feature, times(1)).setDependencies( new HashSet<String>(){{add("first-test-feature"); add("second-test-feature");}} ); verify(feature, times(1)).setFeatureLocation(new Path(directory)); }
@Test (expected = UnzipFeatureException.class) public void checkUnzipFeatureException() throws Exception { UnzipFeatureActor actor = new UnzipFeatureActor(); UnzipFeatureWrapper wrapper = mock(UnzipFeatureWrapper.class); when(wrapper.getFeature()).thenThrow(ReadValueException.class); actor.unzip(wrapper); fail(); }
@Test public void checkUnzipOnUnsupportedFeatureFormat() throws Exception { UnzipFeatureActor actor = new UnzipFeatureActor(); UnzipFeatureWrapper wrapper = mock(UnzipFeatureWrapper.class); IFeature feature = mock(IFeature.class); when(feature.getName()).thenReturn("test-feature"); when(feature.getDependencies()).thenReturn(null); String fileName = "target/test-classes/unsupported-test-feature-VERSION-archive.zip"; when(feature.getFeatureLocation()).thenReturn( new Path(fileName) ); when(wrapper.getFeature()).thenReturn(feature); actor.unzip(wrapper); verify(feature, times(1)).setFailed(true); }
@Test public void checkUnzipOnBrokenFeatureFormat() throws Exception { UnzipFeatureActor actor = new UnzipFeatureActor(); UnzipFeatureWrapper wrapper = mock(UnzipFeatureWrapper.class); IFeature feature = mock(IFeature.class); when(feature.getName()).thenReturn("test-feature"); when(feature.getDependencies()).thenReturn(null); String fileName = "target/test-classes/broken-test-feature-VERSION-archive.zip"; when(feature.getFeatureLocation()).thenReturn( new Path(fileName) ); when(wrapper.getFeature()).thenReturn(feature); actor.unzip(wrapper); verify(feature, times(1)).setFailed(true); }