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.service;
23 import static org.junit.Assert.assertEquals;
24 import static org.onap.so.adapters.vevnfm.service.SubscribeSender.SLASH;
25 import static org.springframework.http.HttpHeaders.CONTENT_TYPE;
26 import static org.springframework.test.web.client.ExpectedCount.once;
27 import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
28 import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
31 import org.hamcrest.CoreMatchers;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.aai.domain.yang.EsrSystemInfo;
36 import org.onap.so.adapters.vevnfm.configuration.StartupConfiguration;
37 import org.onap.so.adapters.vevnfm.exception.VeVnfmException;
38 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.beans.factory.annotation.Value;
41 import org.springframework.boot.test.context.SpringBootTest;
42 import org.springframework.http.HttpMethod;
43 import org.springframework.http.HttpStatus;
44 import org.springframework.http.MediaType;
45 import org.springframework.test.context.ActiveProfiles;
46 import org.springframework.test.context.junit4.SpringRunner;
47 import org.springframework.test.web.client.MockRestServiceServer;
48 import org.springframework.web.client.RestTemplate;
51 @RunWith(SpringRunner.class)
52 @ActiveProfiles(StartupConfiguration.TEST_PROFILE)
53 public class SubscribeSenderTest {
55 private static final String URL = "lh";
56 private static final String ID = "1a2s3d4f";
57 private static final String JSON = "{\"id\":\"" + ID + "\"}";
59 private static final Gson GSON;
62 final GsonBuilder builder = new GsonBuilder();
63 builder.serializeNulls();
64 GSON = builder.create();
67 @Value("${vnfm.subscription}")
68 private String vnfmSubscription;
71 private SubscribeSender sender;
74 private RestTemplate restTemplate;
76 private MockRestServiceServer mockRestServer;
80 mockRestServer = MockRestServiceServer.bindTo(restTemplate).build();
84 public void testSuccess() throws VeVnfmException {
86 final EsrSystemInfo info = new EsrSystemInfo();
87 info.setServiceUrl(URL);
88 final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
90 mockRestServer.expect(once(), requestTo(SLASH + info.getServiceUrl() + vnfmSubscription))
91 .andExpect(header(CONTENT_TYPE, CoreMatchers.containsString(MediaType.APPLICATION_JSON_VALUE)))
92 .andExpect(method(HttpMethod.POST)).andExpect(content().json(GSON.toJson(request)))
93 .andRespond(withStatus(HttpStatus.CREATED).body(JSON).contentType(MediaType.APPLICATION_JSON));
96 final String id = sender.send(info, request);
99 mockRestServer.verify();
100 assertEquals(ID, id);