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 testVtpRunTests() throws Exception {
66 new MockUp<OpenRemoteCli>() {
69 public Result run(String[] args) {
70 Result result = Result.newBuilder().
79 MockUp mockReq = new MockUp<HttpServletRequest>() {
82 public ServletInputStream getInputStream() throws IOException {
83 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(
84 "{\"csar\"=\"VoLTE.csar\"}".getBytes());
86 return new ServletInputStream(){
87 public int read() throws IOException {
88 return byteArrayInputStream.read();
92 public boolean isFinished() {
97 public boolean isReady() {
102 public void setReadListener(ReadListener arg0) {
109 Response result = vtpResource.runTest("csar-validate", (HttpServletRequest) mockReq.getMockInstance());
110 assertEquals(200, result.getStatus());