2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.retiredcustomer;
24 import com.att.eelf.configuration.EELFLogger;
25 import com.att.eelf.configuration.EELFManager;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.aai.introspection.Version;
30 import org.onap.aai.rest.retired.RetiredConsumer;
32 import javax.ws.rs.core.*;
35 import static org.junit.Assert.assertEquals;
36 import static org.junit.Assert.assertNotNull;
37 import static org.mockito.Matchers.anyObject;
38 import static org.mockito.Mockito.when;
40 public abstract class RetiredConsumerTest {
42 protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json");
44 private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>();
47 VALID_HTTP_STATUS_CODES.add(200);
48 VALID_HTTP_STATUS_CODES.add(201);
49 VALID_HTTP_STATUS_CODES.add(204);
52 protected RetiredConsumer retiredConsumer;
53 protected HttpHeaders httpHeaders;
54 protected UriInfo uriInfo;
56 private MultivaluedMap<String, String> headersMultiMap;
57 private MultivaluedMap<String, String> queryParameters;
59 private List<String> aaiRequestContextList;
61 private List<MediaType> outputMediaTypes;
63 private static final EELFLogger logger = EELFManager.getInstance().getLogger(RetiredConsumer.class.getName());
67 logger.info("Starting the setup for the integration tests of Rest Endpoints");
69 retiredConsumer = getRetiredConsumer();
70 httpHeaders = Mockito.mock(HttpHeaders.class);
71 uriInfo = Mockito.mock(UriInfo.class);
73 headersMultiMap = new MultivaluedHashMap<>();
74 queryParameters = Mockito.spy(new MultivaluedHashMap<>());
76 headersMultiMap.add("X-FromAppId", "JUNIT");
77 headersMultiMap.add("X-TransactionId", UUID.randomUUID().toString());
78 headersMultiMap.add("Real-Time", "true");
79 headersMultiMap.add("Accept", "application/json");
80 headersMultiMap.add("aai-request-context", "");
82 outputMediaTypes = new ArrayList<>();
83 outputMediaTypes.add(APPLICATION_JSON);
85 aaiRequestContextList = new ArrayList<>();
86 aaiRequestContextList.add("");
88 when(httpHeaders.getAcceptableMediaTypes()).thenReturn(outputMediaTypes);
89 when(httpHeaders.getRequestHeaders()).thenReturn(headersMultiMap);
91 when(httpHeaders.getRequestHeader("aai-request-context")).thenReturn(aaiRequestContextList);
94 when(uriInfo.getQueryParameters()).thenReturn(queryParameters);
95 when(uriInfo.getQueryParameters(false)).thenReturn(queryParameters);
97 // TODO - Check if this is valid since RemoveDME2QueryParameters seems to be very unreasonable
98 Mockito.doReturn(null).when(queryParameters).remove(anyObject());
100 when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON);
104 public void testRetiredForAllEndPoints(){
105 when(uriInfo.getPath()).thenReturn("/aai/v3/cloud-infrastructure/pservers/pserver/test-pserver1");
107 Response response = retiredConsumer.createMessageGet(Version.getLatest().toString(), httpHeaders, uriInfo, null);
108 assertNotNull(response);
109 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
111 response = retiredConsumer.createMessagePost(Version.getLatest().toString(), httpHeaders, uriInfo, null);
112 assertNotNull(response);
113 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
115 response = retiredConsumer.createMessagePatch(Version.getLatest().toString(), httpHeaders, uriInfo, null);
116 assertNotNull(response);
117 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
119 response = retiredConsumer.createMessagePut(Version.getLatest().toString(), httpHeaders, uriInfo, null);
120 assertNotNull(response);
121 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
123 response = retiredConsumer.createMessageDelete(Version.getLatest().toString(), httpHeaders, uriInfo, null);
124 assertNotNull(response);
125 assertEquals(Response.Status.GONE.getStatusCode(), response.getStatus());
128 public abstract RetiredConsumer getRetiredConsumer();