2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. 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=========================================================
20 package org.onap.aai.retiredcustomer;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.Mockito;
27 import org.onap.aai.introspection.Version;
28 import org.onap.aai.rest.retired.RetiredConsumer;
30 import javax.ws.rs.core.*;
33 import static org.junit.Assert.assertEquals;
34 import static org.junit.Assert.assertNotNull;
35 import static org.mockito.Matchers.anyObject;
36 import static org.mockito.Mockito.when;
38 public abstract class RetiredConsumerTest {
40 protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json");
42 private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>();
45 VALID_HTTP_STATUS_CODES.add(200);
46 VALID_HTTP_STATUS_CODES.add(201);
47 VALID_HTTP_STATUS_CODES.add(204);
50 protected RetiredConsumer retiredConsumer;
51 protected HttpHeaders httpHeaders;
52 protected UriInfo uriInfo;
54 private MultivaluedMap<String, String> headersMultiMap;
55 private MultivaluedMap<String, String> queryParameters;
57 private List<String> aaiRequestContextList;
59 private List<MediaType> outputMediaTypes;
61 private static final EELFLogger logger = EELFManager.getInstance().getLogger(RetiredConsumer.class.getName());
65 logger.info("Starting the setup for the integration tests of Rest Endpoints");
67 retiredConsumer = getRetiredConsumer();
68 httpHeaders = Mockito.mock(HttpHeaders.class);
69 uriInfo = Mockito.mock(UriInfo.class);
71 headersMultiMap = new MultivaluedHashMap<>();
72 queryParameters = Mockito.spy(new MultivaluedHashMap<>());
74 headersMultiMap.add("X-FromAppId", "JUNIT");
75 headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString());
76 headersMultiMap.add("Real-Time", "true");
77 headersMultiMap.add("Accept", "application/json");
78 headersMultiMap.add("aai-request-context", "");
80 outputMediaTypes = new ArrayList<>();
81 outputMediaTypes.add(APPLICATION_JSON);
83 aaiRequestContextList = new ArrayList<>();
84 aaiRequestContextList.add("");
86 when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes);
87 when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap);
89 when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList);
92 when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
93 when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters);
95 // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable
96 Mockito.doReturn(null).when(queryParameters).remove(anyObject());
98 when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
102 public void testRetiredForAllEndPoints(){
103 when(uriInfo.getPath()).thenReturn("/aai/v3/cloud-infrastructure/pservers/pserver/test-pserver1");
105 Response response = retiredConsumer.createMessageGet(Version.getLatest().toString(), httpHeaders, uriInfo, null);
106 assertNotNull(response);
107 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
109 response = retiredConsumer.createMessagePost(Version.getLatest().toString(), httpHeaders, uriInfo, null);
110 assertNotNull(response);
111 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
113 response = retiredConsumer.createMessagePatch(Version.getLatest().toString(), httpHeaders, uriInfo, null);
114 assertNotNull(response);
115 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
117 response = retiredConsumer.createMessagePut(Version.getLatest().toString(), httpHeaders, uriInfo, null);
118 assertNotNull(response);
119 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
121 response = retiredConsumer.createMessageDelete(Version.getLatest().toString(), httpHeaders, uriInfo, null);
122 assertNotNull(response);
123 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
126 public abstract RetiredConsumer getRetiredConsumer();