2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Samsung. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.vevnfm.subscription;
23 import static org.junit.Assert.assertTrue;
24 import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
25 import static org.springframework.test.web.client.ExpectedCount.once;
26 import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
27 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import org.hamcrest.CoreMatchers;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
35 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.beans.factory.annotation.Value;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.MediaType;
42 import org.springframework.test.context.ActiveProfiles;
43 import org.springframework.test.context.junit4.SpringRunner;
44 import org.springframework.test.web.client.MockRestServiceServer;
45 import org.springframework.web.client.RestTemplate;
48 @RunWith(SpringRunner.class)
49 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
50 public class SubscribeSenderTest {
52 private static final String SLASH = "/";
53 private static final String MINIMAL_JSON_CONTENT = "{}";
55 private static final Gson GSON;
58 final GsonBuilder builder = new GsonBuilder();
59 builder.serializeNulls();
60 GSON = builder.create();
63 @Value("${vnfm.subscription}")
64 private String vnfmSubscription;
67 private SubscribeSender sender;
70 private RestTemplate restTemplate;
72 private MockRestServiceServer mockRestServer;
76 mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
80 public void testSuccess() {
82 final String endpoint = "lh";
83 final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
85 mockRestServer.expect(once(), requestTo(SLASH + endpoint + vnfmSubscription))
86 .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE)))
87 .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request)))
88 .andRespond(withStatus(HttpStatus.CREATED).body(MINIMAL_JSON_CONTENT));
91 final boolean done = sender.send(endpoint, request);
95 mockRestServer.verify();