2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
22 package org.onap.aaf.auth.locate.service;
\r
24 import static org.junit.Assert.assertEquals;
\r
25 import static org.mockito.Matchers.any;
\r
26 import static org.mockito.Mockito.when;
\r
28 import java.util.ArrayList;
\r
29 import java.util.List;
\r
31 import org.junit.Before;
\r
32 import org.junit.Test;
\r
33 import org.mockito.Mock;
\r
34 import org.mockito.MockitoAnnotations;
\r
35 import org.onap.aaf.auth.dao.cass.LocateDAO;
\r
36 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
\r
37 import org.onap.aaf.auth.env.AuthzTrans;
\r
38 import org.onap.aaf.auth.layer.Result;
\r
39 import org.onap.aaf.auth.locate.AAF_Locate;
\r
40 import org.onap.aaf.auth.locate.mapper.Mapper;
\r
41 import org.onap.aaf.misc.env.APIException;
\r
43 import locate.v1_0.MgmtEndpoint;
\r
44 import locate.v1_0.MgmtEndpoints;
\r
46 public class JU_LocateServiceImplTest {
\r
48 // Extend, because I don't want a "setter" in the original. Compromised with a protected...
\r
49 private final class LocateServiceImplExtension extends LocateServiceImpl {
\r
50 private LocateServiceImplExtension(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException {
\r
51 super(trans, locate, mapper);
\r
53 public void set(LocateDAO ld) {
\r
59 private AuthzTrans trans;
\r
61 private AAF_Locate aaf_locate;
\r
63 private LocateDAO locateDAO;
\r
65 private Mapper mapper;
\r
67 private Result<List<Data>> result;
\r
69 private Result endPointResult;
\r
71 private MgmtEndpoints meps;
\r
73 private MgmtEndpoint mgmtEndPoint;
\r
76 public void setup() {
\r
77 MockitoAnnotations.initMocks(this);
\r
81 public void test() throws APIException {
\r
82 LocateServiceImplExtension locateServiceImpl = new LocateServiceImplExtension(trans, aaf_locate, mapper);
\r
83 locateServiceImpl.set(locateDAO);
\r
85 assertEquals(mapper, locateServiceImpl.mapper());
\r
87 when(locateDAO.readByName(trans, "http")).thenReturn(result);
\r
88 when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
\r
90 Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
\r
92 assertEquals(endPointResult, output);
\r
94 List<MgmtEndpoint> mgmtEndPoints = new ArrayList<>();
\r
95 mgmtEndPoints.add(mgmtEndPoint);
\r
97 when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
\r
98 when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
\r
99 when(mgmtEndPoint.getPort()).thenReturn(9090);
\r
100 when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
\r
102 when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
\r
103 output = locateServiceImpl.putMgmtEndPoints(trans, meps);
\r
105 assertEquals(output.toString(), Result.ok().toString());
\r
107 when(trans.fish(any())).thenReturn(true);
\r
108 Data data = new LocateDAO.Data();
\r
109 when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
\r
110 output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
\r
112 assertEquals(output.toString(), Result.ok().toString());
\r