1 package org.openecomp.portalapp.portal.test.service;
 
   3 import static org.junit.Assert.assertTrue;
 
   5 import java.io.ByteArrayInputStream;
 
   6 import java.io.IOException;
 
   7 import java.io.InputStream;
 
   8 import java.util.jar.Attributes;
 
  10 import javax.servlet.ServletContext;
 
  12 import org.junit.Before;
 
  13 import org.junit.Test;
 
  14 import org.mockito.InjectMocks;
 
  15 import org.mockito.Mock;
 
  16 import org.mockito.Mockito;
 
  17 import org.mockito.MockitoAnnotations;
 
  18 import org.openecomp.portalapp.portal.service.ManifestServiceImpl;
 
  20 public class ManifestServiceImplTest {
 
  23         ServletContext context;
 
  26         ServletContext context1 = null;
 
  29         ManifestServiceImpl manifestServiceImpl = new ManifestServiceImpl();
 
  33                 MockitoAnnotations.initMocks(this);
 
  36         NullPointerException nullPointerException = new NullPointerException();
 
  39         public void getWebappManifestTest() throws IOException {
 
  40                 final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
 
  41                 InputStream inputStream = new ByteArrayInputStream("test data".getBytes());
 
  42                 Mockito.when(context.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenReturn(inputStream);
 
  43                 Attributes attributes = manifestServiceImpl.getWebappManifest();
 
  44                 assertTrue(attributes.size() == 0);
 
  47         @Test(expected = java.lang.NullPointerException.class)
 
  48         public void getWebappManifestExceptionTest() throws IOException {
 
  49                 final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
 
  50                 InputStream inputStream = new ByteArrayInputStream("test data".getBytes());
 
  51                 Mockito.when(context1.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenThrow(nullPointerException);
 
  52                 Attributes attributes = manifestServiceImpl.getWebappManifest();
 
  53                 assertTrue(attributes.size() == 0);