diff options
author | Sai Gandham <sg481n@att.com> | 2018-10-02 10:13:29 -0500 |
---|---|---|
committer | Sai Gandham <sg481n@att.com> | 2018-10-02 10:13:48 -0500 |
commit | aebee0032fe3d636f5c077df7bb5ee705bb38c44 (patch) | |
tree | 35746bdad7be44acd2fa85053258339766d5fd75 | |
parent | 535a03fb6b15ce3f2e923c71840d43c80f6f6aa1 (diff) |
Update junits for locate and gui
Issue-ID: AAF-111
Change-Id: Ie13e13b825d1f3be04fc65ab980806d2f0fdbffc
Signed-off-by: Sai Gandham <sg481n@att.com>
8 files changed, 512 insertions, 142 deletions
diff --git a/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_FormTest.java b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_FormTest.java new file mode 100644 index 00000000..0f348f39 --- /dev/null +++ b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_FormTest.java @@ -0,0 +1,63 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.gui; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.misc.xgen.Cache; +import org.onap.aaf.misc.xgen.html.HTMLGen; + +public class JU_FormTest { + + @Mock + private Cache<HTMLGen> cache; + + @Mock + private HTMLGen hgen; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void test() throws Exception { + when(hgen.incr("p", "class=preamble")).thenReturn(hgen); + when(hgen.text("preamable")).thenReturn(hgen); + when(hgen.tagOnly("input", "type=submit", "value=Submit")).thenReturn(hgen); + when(hgen.tagOnly("input", "type=reset", "value=Reset")).thenReturn(hgen); + + Form form = new Form(false, new BreadCrumbs(null)); + + assertThat(form.idattrs(), equalTo(new String[] { "breadcrumbs" })); + + assertThat(form.preamble("preamable"), equalTo(form)); + + form.code(cache, hgen); + } + +} diff --git a/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_TableTest.java b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_TableTest.java new file mode 100644 index 00000000..b13f6d30 --- /dev/null +++ b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/JU_TableTest.java @@ -0,0 +1,71 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.gui; + +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.IOException; +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.gui.Table.Data; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.TransStore; +import org.onap.aaf.misc.xgen.Cache; +import org.onap.aaf.misc.xgen.Code; +import org.onap.aaf.misc.xgen.html.HTMLGen; + +public class JU_TableTest { + + @Mock + private TransStore trans; + private Code<HTMLGen> other; + @Mock + private Data data; + @Mock + private Cache cache; + @Mock + private HTMLGen hgen; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void test() throws APIException, IOException { + when(hgen.leaf("caption", "class=title")).thenReturn(hgen); + when(hgen.text("title")).thenReturn(hgen); + when(data.headers()).thenReturn(new String[0]); + + Table table = new Table("title", trans, data, other, "name", "attr1", "attr1"); + Table.Cells cells = new Table.Cells(new ArrayList(), ""); + + table.code(cache, hgen); + + verify(hgen).end(); + } + +} diff --git a/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/table/JU_UICellTest.java b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/table/JU_UICellTest.java new file mode 100644 index 00000000..c6b92f7c --- /dev/null +++ b/auth/auth-gui/src/test/java/org/onap/aaf/auth/gui/table/JU_UICellTest.java @@ -0,0 +1,170 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ + +package org.onap.aaf.auth.gui.table; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.aaf.auth.gui.table.CheckBoxCell.ALIGN; +import org.onap.aaf.misc.xgen.html.HTMLGen; + +public class JU_UICellTest { + @Mock + private HTMLGen hgen; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testButtonCell() { + String[] attrs = { "type=button", "value=null", "attribute1", "attribute2" }; + ButtonCell cell = new ButtonCell(null, "attribute1", "attribute2"); + + when(hgen.incr("input", true, attrs)).thenReturn(hgen); + + cell.write(hgen); + + AbsCell.Null.write(hgen); + + assertThat(AbsCell.Null.attrs(), equalTo(new String[0])); + + assertThat(cell.attrs(), equalTo(AbsCell.CENTER)); + + verify(hgen).end(); + } + + @Test + public void testCheckBoxCellWithoutAlign() { + String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" }; + CheckBoxCell cell = new CheckBoxCell("name", "attribute1", "attribute2"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(AbsCell.CENTER)); + + verify(hgen).tagOnly("input", attrs); + } + + @Test + public void testCheckBoxCellWithLeftAlign() { + String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" }; + CheckBoxCell cell = new CheckBoxCell("name", ALIGN.left, "attribute1", "attribute2"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(AbsCell.LEFT)); + + verify(hgen).tagOnly("input", attrs); + } + + @Test + public void testCheckBoxCellWithRightAlign() { + String[] attrs = { "type=checkbox", "name=name", "value=attribute1", "attribute2" }; + CheckBoxCell cell = new CheckBoxCell("name", ALIGN.right, "attribute1", "attribute2"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(AbsCell.RIGHT)); + + verify(hgen).tagOnly("input", attrs); + } + + @Test + public void testRadioCell() { + String[] attrs = { "type=radio", "name=name", "class=attribute1", "value=attribute2" }; + RadioCell cell = new RadioCell("name", "attribute1", "attribute2"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(AbsCell.CENTER)); + + verify(hgen).tagOnly("input", attrs); + } + + @Test + public void testRefCellWithNewWindow() { + String[] attrs = { "href=attribute1", "attribute2", null }; + RefCell cell = new RefCell("name", "attribute1", true, "attribute2"); + + when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(new String[0])); + } + + @Test + public void testRefCellWithoutNewWindow() { + String[] attrs = { "href=attribute1", "attribute2" }; + RefCell cell = new RefCell("name", "attribute1", false, "attribute2"); + + when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(new String[0])); + + } + + @Test + public void testTextAndRefCell() { + String[] attrs = { "href=href", "attribute1", null }; + String[] attributes = { "attribute1" }; + TextAndRefCell cell = new TextAndRefCell("text", "name", "href", true, attributes); + + when(hgen.leaf(HTMLGen.A, attrs)).thenReturn(hgen); + + cell.write(hgen); + + verify(hgen).text("text"); + } + + @Test + public void testTextCell() { + String[] attrs = { "href" }; + TextCell cell = new TextCell("name", "href"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(attrs)); + + verify(hgen).text("name"); + } + + @Test + public void testTextInputCell() { + String[] attrs = { "href" }; + TextInputCell cell = new TextInputCell("name", "textClass", "value"); + + cell.write(hgen); + + assertThat(cell.attrs(), equalTo(new String[0])); + } +} diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java index 03b3ec68..31876fef 100644 --- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/JU_BasicAuthCodeTest.java @@ -18,7 +18,6 @@ * ============LICENSE_END====================================================
*
*/
-
package org.onap.aaf.auth.locate;
import static org.junit.Assert.assertEquals;
@@ -42,75 +41,74 @@ import org.onap.aaf.cadi.principal.X509Principal; import org.onap.aaf.misc.env.LogTarget;
public class JU_BasicAuthCodeTest {
+ @Mock
+ AAFAuthn authn;
- @Mock
- AAFAuthn authn;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- AuthzTrans trans;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ AuthzTrans trans;
- @Mock
- HttpServletRequest req;
+ @Mock
+ HttpServletRequest req;
- @Mock
- HttpServletResponse resp;
+ @Mock
+ HttpServletResponse resp;
- @Mock
- LogTarget error;
+ @Mock
+ LogTarget error;
- @Mock
- LocateFacade facade;
+ @Mock
+ LocateFacade facade;
- @Mock
- BasicPrincipal basicPrincipal;
- @Mock
- X509Principal x509Principal;
+ @Mock
+ BasicPrincipal basicPrincipal;
+ @Mock
+ X509Principal x509Principal;
- @Before
- public void setUp() throws Exception {
- initMocks(this);
- }
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ }
- @Test
- public void testWithNullUserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithNullUserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(null);
- when(trans.error()).thenReturn(error);
+ when(trans.getUserPrincipal()).thenReturn(null);
+ when(trans.error()).thenReturn(error);
- basicAuthCode.handle(trans, req, resp);
- }
+ basicAuthCode.handle(trans, req, resp);
+ }
- @Test
- public void testWithBasicUserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithBasicUserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
+ when(trans.getUserPrincipal()).thenReturn(basicPrincipal);
- basicAuthCode.handle(trans, req, resp);
+ basicAuthCode.handle(trans, req, resp);
- verify(resp).setStatus(HttpStatus.OK_200);
- }
+ verify(resp).setStatus(HttpStatus.OK_200);
+ }
- @Test
- public void testWithX509UserPrincipal() throws Exception {
- BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
- LocateCode locateCode = basicAuthCode.clone(facade, false);
+ @Test
+ public void testWithX509UserPrincipal() throws Exception {
+ BasicAuthCode basicAuthCode = new BasicAuthCode(authn, facade);
+ LocateCode locateCode = basicAuthCode.clone(facade, false);
- assertEquals(locateCode.desc(), basicAuthCode.desc());
+ assertEquals(locateCode.desc(), basicAuthCode.desc());
- when(trans.getUserPrincipal()).thenReturn(x509Principal);
- when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
+ when(trans.getUserPrincipal()).thenReturn(x509Principal);
+ when(req.getHeader("Authorization")).thenReturn("Basic 76//76");
- basicAuthCode.handle(trans, req, resp);
+ basicAuthCode.handle(trans, req, resp);
- verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
- }
+ verify(resp).setStatus(HttpStatus.FORBIDDEN_403);
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/api/JU_API_AAFTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/api/JU_API_AAFTest.java new file mode 100644 index 00000000..ef8a1dc4 --- /dev/null +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/api/JU_API_AAFTest.java @@ -0,0 +1,71 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.auth.locate.api; + +import static org.junit.Assert.fail; +import static org.mockito.MockitoAnnotations.initMocks; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Answers; +import org.mockito.Mock; +import org.onap.aaf.auth.locate.AAF_Locate; +import org.onap.aaf.auth.locate.facade.LocateFacade; + +public class JU_API_AAFTest { + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private AAF_Locate gwAPI; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private LocateFacade facade; + + @Before + public void setUp() throws Exception { + initMocks(this); + } + + @Test + public void testAPI_AAFAccess() throws Exception { + try { + API_AAFAccess.init(gwAPI, facade); + } catch (Exception e) { + fail("There should be no exception as Mocks are used"); + } + } + + @Test + public void testAPI_Find() throws Exception { + try { + API_Find.init(gwAPI, facade); + } catch (Exception e) { + fail("There should be no exception as Mocks are used"); + } + } + + @Test + public void testAPI_API() throws Exception { + try { + API_Api.init(gwAPI, facade); + } catch (Exception e) { + fail("There should be no exception as Mocks are used"); + } + } +} diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java index 37db5edc..26bea940 100644 --- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/mapper/JU_Mapper_1_0Test.java @@ -18,7 +18,6 @@ * ============LICENSE_END====================================================
*
*/
-
package org.onap.aaf.auth.locate.mapper;
import static org.junit.Assert.assertEquals;
@@ -36,31 +35,31 @@ import locate_local.v1_0.Out; public class JU_Mapper_1_0Test {
- @Before
- public void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
- }
+ }
- @Test
- public void testGetClasses() {
- Mapper_1_1 mapper = new Mapper_1_1();
- assertEquals(InRequest.class, mapper.getClass(API.IN_REQ));
- assertEquals(Out.class, mapper.getClass(API.OUT));
- assertEquals(Error.class, mapper.getClass(API.ERROR));
- assertEquals(Void.class, mapper.getClass(API.VOID));
- assertEquals(Endpoints.class, mapper.getClass(API.ENDPOINTS));
- assertEquals(MgmtEndpoints.class, mapper.getClass(API.MGMT_ENDPOINTS));
- }
+ @Test
+ public void testGetClasses() {
+ Mapper_1_1 mapper = new Mapper_1_1();
+ assertEquals(InRequest.class, mapper.getClass(API.IN_REQ));
+ assertEquals(Out.class, mapper.getClass(API.OUT));
+ assertEquals(Error.class, mapper.getClass(API.ERROR));
+ assertEquals(Void.class, mapper.getClass(API.VOID));
+ assertEquals(Endpoints.class, mapper.getClass(API.ENDPOINTS));
+ assertEquals(MgmtEndpoints.class, mapper.getClass(API.MGMT_ENDPOINTS));
+ }
- @Test
- public void testNewInstance() {
- Mapper_1_1 mapper = new Mapper_1_1();
- assertTrue(mapper.newInstance(API.IN_REQ) instanceof InRequest);
- assertTrue(mapper.newInstance(API.OUT) instanceof Out);
- assertTrue(mapper.newInstance(API.ERROR) instanceof Error);
- assertTrue(mapper.newInstance(API.ENDPOINTS) instanceof Endpoints);
- assertTrue(mapper.newInstance(API.MGMT_ENDPOINTS) instanceof MgmtEndpoints);
- assertEquals(null, mapper.newInstance(API.VOID));
- }
+ @Test
+ public void testNewInstance() {
+ Mapper_1_1 mapper = new Mapper_1_1();
+ assertTrue(mapper.newInstance(API.IN_REQ) instanceof InRequest);
+ assertTrue(mapper.newInstance(API.OUT) instanceof Out);
+ assertTrue(mapper.newInstance(API.ERROR) instanceof Error);
+ assertTrue(mapper.newInstance(API.ENDPOINTS) instanceof Endpoints);
+ assertTrue(mapper.newInstance(API.MGMT_ENDPOINTS) instanceof MgmtEndpoints);
+ assertEquals(null, mapper.newInstance(API.VOID));
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java index d6712e22..c66de60b 100644 --- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/service/JU_LocateServiceImplTest.java @@ -18,7 +18,6 @@ * ============LICENSE_END====================================================
*
*/
-
package org.onap.aaf.auth.locate.service;
import static org.junit.Assert.assertEquals;
@@ -45,71 +44,71 @@ import locate.v1_0.MgmtEndpoints; public class JU_LocateServiceImplTest {
- // Extend, because I don't want a "setter" in the original. Compromised with a protected...
- private final class LocateServiceImplExtension extends LocateServiceImpl {
- private LocateServiceImplExtension(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException {
- super(trans, locate, mapper);
- }
- public void set(LocateDAO ld) {
- locateDAO=ld;
- }
- }
-
- @Mock
- private AuthzTrans trans;
- @Mock
- private AAF_Locate aaf_locate;
- @Mock
- private LocateDAO locateDAO;
- @Mock
- private Mapper mapper;
- @Mock
- private Result<List<Data>> result;
- @Mock
- private Result endPointResult;
- @Mock
- private MgmtEndpoints meps;
- @Mock
- private MgmtEndpoint mgmtEndPoint;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void test() throws APIException {
- LocateServiceImplExtension locateServiceImpl = new LocateServiceImplExtension(trans, aaf_locate, mapper);
- locateServiceImpl.set(locateDAO);
-
- assertEquals(mapper, locateServiceImpl.mapper());
-
- when(locateDAO.readByName(trans, "http")).thenReturn(result);
- when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
-
- Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
-
- assertEquals(endPointResult, output);
-
- List<MgmtEndpoint> mgmtEndPoints = new ArrayList<>();
- mgmtEndPoints.add(mgmtEndPoint);
-
- when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
- when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
- when(mgmtEndPoint.getPort()).thenReturn(9090);
- when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
-
- when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
- output = locateServiceImpl.putMgmtEndPoints(trans, meps);
-
- assertEquals(output.toString(), Result.ok().toString());
-
- when(trans.fish(any())).thenReturn(true);
- Data data = new LocateDAO.Data();
- when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
- output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
-
- assertEquals(output.toString(), Result.ok().toString());
- }
+ // Extend, because I don't want a "setter" in the original. Compromised with a protected...
+ private final class LocateServiceImplExtension extends LocateServiceImpl {
+ private LocateServiceImplExtension(AuthzTrans trans, AAF_Locate locate, Mapper mapper) throws APIException {
+ super(trans, locate, mapper);
+ }
+ public void set(LocateDAO ld) {
+ locateDAO=ld;
+ }
+ }
+
+ @Mock
+ private AuthzTrans trans;
+ @Mock
+ private AAF_Locate aaf_locate;
+ @Mock
+ private LocateDAO locateDAO;
+ @Mock
+ private Mapper mapper;
+ @Mock
+ private Result<List<Data>> result;
+ @Mock
+ private Result endPointResult;
+ @Mock
+ private MgmtEndpoints meps;
+ @Mock
+ private MgmtEndpoint mgmtEndPoint;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void test() throws APIException {
+ LocateServiceImplExtension locateServiceImpl = new LocateServiceImplExtension(trans, aaf_locate, mapper);
+ locateServiceImpl.set(locateDAO);
+
+ assertEquals(mapper, locateServiceImpl.mapper());
+
+ when(locateDAO.readByName(trans, "http")).thenReturn(result);
+ when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
+
+ Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
+
+ assertEquals(endPointResult, output);
+
+ List<MgmtEndpoint> mgmtEndPoints = new ArrayList<>();
+ mgmtEndPoints.add(mgmtEndPoint);
+
+ when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
+ when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
+ when(mgmtEndPoint.getPort()).thenReturn(9090);
+ when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
+
+ when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
+ output = locateServiceImpl.putMgmtEndPoints(trans, meps);
+
+ assertEquals(output.toString(), Result.ok().toString());
+
+ when(trans.fish(any())).thenReturn(true);
+ Data data = new LocateDAO.Data();
+ when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
+ output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
+
+ assertEquals(output.toString(), Result.ok().toString());
+ }
}
diff --git a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/validation/JU_LocateValidatorTest.java b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/validation/JU_LocateValidatorTest.java index 5f75a799..0339f318 100644 --- a/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/validation/JU_LocateValidatorTest.java +++ b/auth/auth-locate/src/test/java/org/onap/aaf/auth/locate/validation/JU_LocateValidatorTest.java @@ -18,7 +18,6 @@ * ============LICENSE_END====================================================
*
*/
-
package org.onap.aaf.auth.locate.validation;
import static org.junit.Assert.assertEquals;
|