X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=datafilecollector%2Fsrc%2Ftest%2Fjava%2Forg%2Foran%2Fdatafile%2Fhttp%2FDfcHttpClientTest.java;h=4d605afe222e410408e5ffefb03588781b7bfbf1;hb=69316aa635c8f28557a38aab90e3362295d0725f;hp=0e9a8d0bc0984e4a02e9d0a89e2017da2fc7ea7a;hpb=3a9d09f02a50cf1174a6e9ccf8e7d0af88a7ecf3;p=nonrtric%2Fplt%2Franpm.git diff --git a/datafilecollector/src/test/java/org/oran/datafile/http/DfcHttpClientTest.java b/datafilecollector/src/test/java/org/oran/datafile/http/DfcHttpClientTest.java index 0e9a8d0..4d605af 100644 --- a/datafilecollector/src/test/java/org/oran/datafile/http/DfcHttpClientTest.java +++ b/datafilecollector/src/test/java/org/oran/datafile/http/DfcHttpClientTest.java @@ -29,18 +29,16 @@ import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.net.URISyntaxException; import java.nio.file.Path; -import org.apache.hc.core5.net.URIBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.oran.datafile.exceptions.DatafileTaskException; import org.oran.datafile.model.FileServerData; +import org.oran.datafile.oauth2.SecurityContext; import reactor.core.publisher.Flux; import reactor.netty.http.client.HttpClientConfig; @@ -52,8 +50,6 @@ class DfcHttpClientTest { private static final String PASSWORD = "123"; private static final String XNF_ADDRESS = "127.0.0.1"; private static final int PORT = 80; - private static final String JWT_PASSWORD = "thisIsThePassword"; - private static String ACCESS_TOKEN = "access_token"; @Mock private Path pathMock; @@ -62,7 +58,8 @@ class DfcHttpClientTest { @BeforeEach public void setup() { - dfcHttpClientSpy = spy(new DfcHttpClient(createFileServerData())); + SecurityContext ctx = new SecurityContext(""); + dfcHttpClientSpy = spy(new DfcHttpClient(ctx, createFileServerData())); } @Test @@ -72,17 +69,6 @@ class DfcHttpClientTest { assertEquals(HttpUtils.basicAuthContent(USERNAME, PASSWORD), config.headers().get("Authorization")); } - @Test - void openConnection_failedBasicAuthSetupThrowException() { - FileServerData serverData = - FileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password("").port(PORT).build(); - - DfcHttpClient dfcHttpClientSpy = spy(new DfcHttpClient(serverData)); - - assertThatThrownBy(() -> dfcHttpClientSpy.open()) - .hasMessageContaining("Not sufficient basic auth data for file."); - } - @Test void collectFile_AllOk() throws Exception { String REMOTE_FILE = "any"; @@ -101,27 +87,6 @@ class DfcHttpClientTest { verify(dfcHttpClientSpy, times(1)).isDownloadFailed(any()); } - @Test - void collectFile_AllOkWithJWTToken() throws Exception { - dfcHttpClientSpy = spy(new DfcHttpClient(fileServerDataWithJWTToken())); - String REMOTE_FILE = "any"; - Flux fis = Flux.just(new ByteArrayInputStream("ReturnedString".getBytes())); - - dfcHttpClientSpy.open(); - HttpClientConfig config = dfcHttpClientSpy.client.configuration(); - assertEquals(HttpUtils.jwtAuthContent(JWT_PASSWORD), config.headers().get("Authorization")); - - when(dfcHttpClientSpy.getServerResponse(any())).thenReturn(fis); - doReturn(false).when(dfcHttpClientSpy).isDownloadFailed(any()); - - dfcHttpClientSpy.collectFile(REMOTE_FILE, pathMock); - dfcHttpClientSpy.close(); - - verify(dfcHttpClientSpy, times(1)).getServerResponse(ArgumentMatchers.eq(REMOTE_FILE)); - verify(dfcHttpClientSpy, times(1)).processDataFromServer(any(), any(), any()); - verify(dfcHttpClientSpy, times(1)).isDownloadFailed(any()); - } - @Test void collectFile_No200ResponseWriteToErrorMessage() throws DatafileTaskException { String ERROR_RESPONSE = "This is unexpected message"; @@ -149,11 +114,4 @@ class DfcHttpClientTest { return FileServerData.builder().serverAddress(XNF_ADDRESS).userId(USERNAME).password(PASSWORD).port(PORT) .build(); } - - private FileServerData fileServerDataWithJWTToken() throws URISyntaxException { - String query = "?" + ACCESS_TOKEN + "=" + JWT_PASSWORD; - - return FileServerData.builder().serverAddress(XNF_ADDRESS).userId("").password("").port(PORT) - .queryParameters(new URIBuilder(query).getQueryParams()).build(); - } }