summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common-test/src/main/java/org/openecomp/portalapp/portal/test/service/ManifestServiceImplTest.java
blob: f2b6036eff24f0e1d4f84d5400590bed74b09264 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package org.openecomp.portalapp.portal.test.service;

import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.jar.Attributes;

import javax.servlet.ServletContext;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.portalapp.portal.service.ManifestServiceImpl;

public class ManifestServiceImplTest {

	@Mock
	ServletContext context;

	@Mock
	ServletContext context1 = null;

	@InjectMocks
	ManifestServiceImpl manifestServiceImpl = new ManifestServiceImpl();

	@Before
	public void setup() {
		MockitoAnnotations.initMocks(this);
	}

	NullPointerException nullPointerException = new NullPointerException();

	@Test
	public void getWebappManifestTest() throws IOException {
		final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
		InputStream inputStream = new ByteArrayInputStream("test data".getBytes());
		Mockito.when(context.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenReturn(inputStream);
		Attributes attributes = manifestServiceImpl.getWebappManifest();
		assertTrue(attributes.size() == 0);
	}

	@Test(expected = java.lang.NullPointerException.class)
	public void getWebappManifestExceptionTest() throws IOException {
		final String MANIFEST_RESOURCE_PATH = "/META-INF/MANIFEST.MF";
		InputStream inputStream = new ByteArrayInputStream("test data".getBytes());
		Mockito.when(context1.getResourceAsStream(MANIFEST_RESOURCE_PATH)).thenThrow(nullPointerException);
		Attributes attributes = manifestServiceImpl.getWebappManifest();
		assertTrue(attributes.size() == 0);
	}
}