2 * Copyright 2018 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vnfsdk.marketplace.resource;
19 import static org.junit.Assert.assertEquals;
21 import java.io.ByteArrayInputStream;
22 import java.io.IOException;
24 import javax.servlet.ReadListener;
25 import javax.servlet.ServletInputStream;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.ws.rs.core.Response;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.open.infc.grpc.Result;
32 import org.open.infc.grpc.client.OpenRemoteCli;
37 public class VTPResourceTest {
38 private VTPResource vtpResource = null;
43 vtpResource = new VTPResource();
46 public void testVtpGetTests() throws Exception {
47 new MockUp<OpenRemoteCli>() {
50 public Result run(String[] args) {
51 Result result = Result.newBuilder().
60 Response result = vtpResource.listTests();
61 assertEquals(200, result.getStatus());
65 public void testVtpGetTestsFailure1() throws Exception {
66 new MockUp<OpenRemoteCli>() {
69 public Result run(String[] args) {
70 Result result = Result.newBuilder().
78 Response result = vtpResource.listTests();
79 assertEquals(500, result.getStatus());
83 public void testVtpGetTestsFailure2() throws Exception {
84 new MockUp<OpenRemoteCli>() {
87 public Result run(String[] args) throws Exception {
88 throw new Exception();
92 Response result = vtpResource.listTests();
93 assertEquals(500, result.getStatus());
97 public void testVtpRunTests() throws Exception {
98 new MockUp<OpenRemoteCli>() {
101 public Result run(String[] args) {
102 Result result = Result.newBuilder().
111 MockUp mockReq = new MockUp<HttpServletRequest>() {
114 public ServletInputStream getInputStream() throws IOException {
115 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
116 "{\"csar\"=\"VoLTE.csar\"}".getBytes());
118 return new ServletInputStream(){
119 public int read() throws IOException {
120 return byteArrayInputStream.read();
124 public boolean isFinished() {
129 public boolean isReady() {
134 public void setReadListener(ReadListener arg0) {
141 Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
142 assertEquals(200, result.getStatus());
146 public void testVtpRunTestsFailure1() throws Exception {
147 new MockUp<OpenRemoteCli>() {
150 public Result run(String[] args) {
151 Result result = Result.newBuilder().
159 MockUp mockReq = new MockUp<HttpServletRequest>() {
162 public ServletInputStream getInputStream() throws IOException {
163 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
164 "{\"csar\"=\"VoLTE.csar\"}".getBytes());
166 return new ServletInputStream(){
167 public int read() throws IOException {
168 return byteArrayInputStream.read();
172 public boolean isFinished() {
177 public boolean isReady() {
182 public void setReadListener(ReadListener arg0) {
189 Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
190 assertEquals(500, result.getStatus());
194 public void testVtpRunTestsFailure2() throws Exception {
195 new MockUp<OpenRemoteCli>() {
198 public Result run(String[] args) throws Exception {
199 throw new Exception();
203 MockUp mockReq = new MockUp<HttpServletRequest>() {
206 public ServletInputStream getInputStream() throws IOException {
207 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
208 "{\"csar\"=\"VoLTE.csar\"}".getBytes());
210 return new ServletInputStream(){
211 public int read() throws IOException {
212 return byteArrayInputStream.read();
216 public boolean isFinished() {
221 public boolean isReady() {
226 public void setReadListener(ReadListener arg0) {
233 Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
234 assertEquals(500, result.getStatus());