X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Faaf%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Faaf%2Fv2_0%2Ftest%2FJU_AAFLocator.java;h=3771013820491478f478490cdd7aa51941f0b2a2;hb=1296352d8eafee57f982a4342ad79ada4aa56d28;hp=4d767c9c63d7bea0012cec4a0137c76bfd9ed68b;hpb=af2d592ebbb96d5f5f55f7322f9ecdfdccfce64e;p=aaf%2Fauthz.git diff --git a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFLocator.java b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFLocator.java index 4d767c9c..37710138 100644 --- a/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFLocator.java +++ b/cadi/aaf/src/test/java/org/onap/aaf/cadi/aaf/v2_0/test/JU_AAFLocator.java @@ -7,9 +7,9 @@ * 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. @@ -56,68 +56,68 @@ import locate.v1_0.Endpoint; import locate.v1_0.Endpoints; public class JU_AAFLocator { - - @Mock private HClient clientMock; - @Mock private Future futureMock; - @Mock private Endpoints endpointsMock; - - private PropAccess access; - - private ByteArrayOutputStream errStream; - - private static final String uriString = "https://example.com"; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - doReturn(futureMock).when(clientMock).futureRead((RosettaDF)any(), eq(TYPE.JSON)); - when(clientMock.timeout()).thenReturn(1); - when(clientMock.getURI()).thenReturn(new URI(uriString)); - when(futureMock.get(1)).thenReturn(true); - - futureMock.value = endpointsMock; - List endpoints = new ArrayList<>(); - endpoints.add(new Endpoint()); - when(endpointsMock.getEndpoint()).thenReturn(endpoints); - - access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); - - errStream = new ByteArrayOutputStream(); - - System.setErr(new PrintStream(errStream)); - } - - @After - public void tearDown() { - System.setErr(System.err); - } - - @AfterClass - public static void tearDownAfterClass() throws Exception { - Field field = SecurityInfoC.class.getDeclaredField("sicMap"); - field.setAccessible(true); - field.set(null, new HashMap<>()); - } - - @Test - public void test() throws CadiException, URISyntaxException, LocatorException { - access.setProperty(Config.CADI_LATITUDE, "38.62"); // St Louis approx lat - access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx lon - SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); - URI locatorURI = new URI("https://somemachine.moc:10/com.att.aaf.service:2.0"); -// AbsAAFLocator al = new AAFLocator(si, locatorURI) { -// @Override -// protected HClient createClient(SecuritySetter ss, URI uri, int connectTimeout) throws LocatorException { -// return clientMock; -// } -// }; - // Start over: This was originally calling a developer machine. -// assertThat(al.refresh(), is(true)); -// when(futureMock.get(1)).thenReturn(false); -// assertThat(al.refresh(), is(false)); -// String errorMessage = errStream.toString().split(": ", 2)[1]; -// assertThat(errorMessage, is("Error reading location information from " + uriString + ": 0 null\n \n")); - } + + @Mock private HClient clientMock; + @Mock private Future futureMock; + @Mock private Endpoints endpointsMock; + + private PropAccess access; + + private ByteArrayOutputStream errStream; + + private static final String uriString = "https://example.com"; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + + doReturn(futureMock).when(clientMock).futureRead((RosettaDF)any(), eq(TYPE.JSON)); + when(clientMock.timeout()).thenReturn(1); + when(clientMock.getURI()).thenReturn(new URI(uriString)); + when(futureMock.get(1)).thenReturn(true); + + futureMock.value = endpointsMock; + List endpoints = new ArrayList<>(); + endpoints.add(new Endpoint()); + when(endpointsMock.getEndpoint()).thenReturn(endpoints); + + access = new PropAccess(new PrintStream(new ByteArrayOutputStream()), new String[0]); + + errStream = new ByteArrayOutputStream(); + + System.setErr(new PrintStream(errStream)); + } + + @After + public void tearDown() { + System.setErr(System.err); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + Field field = SecurityInfoC.class.getDeclaredField("sicMap"); + field.setAccessible(true); + field.set(null, new HashMap<>()); + } + + @Test + public void test() throws CadiException, URISyntaxException, LocatorException { + access.setProperty(Config.CADI_LATITUDE, "38.62"); // St Louis approx lat + access.setProperty(Config.CADI_LONGITUDE, "90.19"); // St Louis approx lon + SecurityInfoC si = SecurityInfoC.instance(access, HttpURLConnection.class); + URI locatorURI = new URI("https://somemachine.moc:10/com.att.aaf.service:2.0"); +// AbsAAFLocator al = new AAFLocator(si, locatorURI) { +// @Override +// protected HClient createClient(SecuritySetter ss, URI uri, int connectTimeout) throws LocatorException { +// return clientMock; +// } +// }; + // Start over: This was originally calling a developer machine. +// assertThat(al.refresh(), is(true)); +// when(futureMock.get(1)).thenReturn(false); +// assertThat(al.refresh(), is(false)); +// String errorMessage = errStream.toString().split(": ", 2)[1]; +// assertThat(errorMessage, is("Error reading location information from " + uriString + ": 0 null\n \n")); + } }