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.aai.domain.yang.EsrSystemInfo;
35 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
36 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.http.HttpMethod;
41 import org.springframework.http.HttpStatus;
42 import org.springframework.http.MediaType;
43 import org.springframework.test.context.ActiveProfiles;
44 import org.springframework.test.context.junit4.SpringRunner;
45 import org.springframework.test.web.client.MockRestServiceServer;
46 import org.springframework.web.client.RestTemplate;
49 @RunWith(SpringRunner.class)
50 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
51 public class SubscribeSenderTest {
53 private static final String SLASH = "/";
54 private static final String MINIMAL_JSON_CONTENT = "{}";
56 private static final Gson GSON;
59 final GsonBuilder builder = new GsonBuilder();
60 builder.serializeNulls();
61 GSON = builder.create();
64 @Value("${vnfm.subscription}")
65 private String vnfmSubscription;
68 private SubscribeSender sender;
71 private RestTemplate restTemplate;
73 private MockRestServiceServer mockRestServer;
77 mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
81 public void testSuccess() {
83 final EsrSystemInfo info = new EsrSystemInfo();
84 info.setServiceUrl("lh");
85 final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
87 mockRestServer.expect(once(), requestTo(SLASH + info.getServiceUrl() + vnfmSubscription))
88 .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE)))
89 .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request)))
90 .andRespond(withStatus(HttpStatus.CREATED).body(MINIMAL_JSON_CONTENT));
93 final boolean done = sender.send(info, request);
97 mockRestServer.verify();