diff options
author | Herbert Eiselt <herbert.eiselt@highstreet-technologies.com> | 2019-02-07 17:50:41 +0100 |
---|---|---|
committer | Herbert Eiselt <herbert.eiselt@highstreet-technologies.com> | 2019-02-07 17:51:11 +0100 |
commit | 12a8c669f52c0e84d580c078cee849b25133b585 (patch) | |
tree | 1a0ddb6cc13f225e8a58833b8975f98b453a8d52 /sdnr/wt/devicemanager/provider/src/test | |
parent | bd2aa3c75e0073ff07fb46b14b8b51926915d5c8 (diff) |
Add sdnr wt devicemanager
Add complete sdnr wireless transport app devicemanager
Change-Id: I433014ee579a3c8833b3b8f84c4087c5f776704f
Issue-ID: SDNC-575
Signed-off-by: Herbert Eiselt <herbert.eiselt@highstreet-technologies.com>
Diffstat (limited to 'sdnr/wt/devicemanager/provider/src/test')
17 files changed, 1622 insertions, 0 deletions
diff --git a/sdnr/wt/devicemanager/provider/src/test/java/ExampleHttpClient.java b/sdnr/wt/devicemanager/provider/src/test/java/ExampleHttpClient.java new file mode 100644 index 000000000..c5426e3b6 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/ExampleHttpClient.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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========================================================================== + ******************************************************************************/ + + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.http.BaseHTTPClient; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.http.BaseHTTPResponse; + +/* + * base... baseURL, e.g. http://10.10.55.11:8432/api/paut/ + * + * usage: this.sendRequest() + * uri... all after the baseURL => request-url=base+uri + * headers: https://developer.mozilla.org/de/docs/Web/HTTP/Headers + * + */ +public class ExampleHttpClient extends BaseHTTPClient{ + + private final String username; + private final String password; + + /* + * for normal http request without ssl client certificate authorization + */ + public ExampleHttpClient(String base, boolean trustAllCerts,String user,String passwd) + { + super(base,trustAllCerts); + this.username=user; + this.password=passwd; + int timeout=60000;//http timeout in ms + this.setTimeout(timeout); + + + } + /* + * for client cert authorization + */ + public ExampleHttpClient(String base, boolean trustAllCerts, String certFilename, String passphrase, + int sslCertType) { + super(base, trustAllCerts, certFilename, passphrase, sslCertType); + this.username=""; + this.password=""; + + } + + + public void doExamplePost(String param1,int param2) throws IOException + { + String uri="network/pnf/id"; + String method="GET"; + String body=String.format("{\"param1\":\"%s\",\"param1\":%d}",param1,param2); + Map<String, String> headers = new HashMap<String,String>(); + headers.put("Accept-Encoding", "utf-8"); + headers.put("Authorization", BaseHTTPClient.getAuthorizationHeaderValue(this.username, this.password)); + BaseHTTPResponse response=this.sendRequest(uri, method, body, headers ); + + if(response.code==BaseHTTPResponse.CODE200) + { + + } + + + } +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/TestMappEquipment.java b/sdnr/wt/devicemanager/provider/src/test/java/TestMappEquipment.java new file mode 100644 index 000000000..fd7773554 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/TestMappEquipment.java @@ -0,0 +1,39 @@ +/******************************************************************************* + * ============LICENSE_START======================================================================== + * ONAP : ccsdk feature sdnr wt + * ================================================================================================= + * Copyright (C) 2019 highstreet technologies GmbH 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========================================================================== + ******************************************************************************/ + +public class TestMappEquipment<T> { + + public static void main(String[] args) { + + /* + MyEquipmentBuilder eb = new MyEquipmentBuilder(); + eb.setAdministrativeState(AdministrativeState.Unlocked); + eb.setCategory((new CategoryBuilder()).setCategory(EquipmentCategory.Rack).build()); + + Equipment e2 = eb.build(); + + String inspect = HtDatabaseEventsService.inspect(e2,0); + System.out.println("Inspect: "+inspect); + + String json = HtDatabaseEventsService.toJson(e2); + System.out.println("JSON: "+json); + */ + + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaePrivateTester.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaePrivateTester.java new file mode 100644 index 000000000..e9ccc53b3 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaePrivateTester.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.dcaeConnector.test; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.net.URLConnection; +import java.security.cert.X509Certificate; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + +public class DcaePrivateTester { + + + public static void test(URL url, boolean readFromServer) throws Exception { + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { + @Override + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType) { + } + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType) { + } + } }; + // Install the all-trusting trust manager + final SSLContext sc = SSLContext.getInstance("TLS"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + // Create all-trusting host name verifier + HostnameVerifier allHostsValid = (hostname, session) -> true; + + // Install the all-trusting host verifier + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + + //URL url = new URL("https://www.google.com"); + URLConnection con = url.openConnection(); + System.out.println("Connection background: "+con.getClass().getName()+" "+url.getHost()); + + if (readFromServer) { + final Reader reader = new InputStreamReader(con.getInputStream()); + final BufferedReader br = new BufferedReader(reader); + String line = ""; + while ((line = br.readLine()) != null) { + System.out.println(line); + } + br.close(); + } /**/ + } // End of main + + + +// httpTestUrl=https://plan.fritz.box:9092/ux/# +// keyStore=etc/clientkeystore +// keyStorePassword=daylight2016 + public static void main(String[] args) { + + String urlString = "https://www.google.de"; + //String urlString = "https://plan.fritz.box:9092/ux/#"; + //String urlString = "http://plan.fritz.box:9091/ux/#"; + //String urlString = "http://127.0.0.1:30000/eventListener/v3"; + + try { + test(new URL(urlString), true); + } catch (Exception e) { + System.out.println("(..something..) failed"); + e.printStackTrace(); + } + /* + System.out.println("Test HTTPS"); + + final HttpsClient httpTestClient; + httpTestClient = new HttpsClient(); + + httpTestClient.testIt( + //"https://plan.fritz.box:9092/ux/#", + "https://www.google.de", + "/home/herbert/odl/distribution-karaf-0.5.1-Boron-SR1/etc/clientkeystore", + "daylight2016" + );/**/ + + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaeTestClient.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaeTestClient.java new file mode 100644 index 000000000..ffc007a06 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/DcaeTestClient.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.dcaeConnector.test; + +import org.onap.ccsdk.features.sdnr.wt.devicemanager.config.impl.DcaeConfig; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeMessages; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeSenderImpl; + +public class DcaeTestClient { + + private static final boolean TESTCOLLECTOR_YES = true; + + public static void main(String[] args) { + + System.out.println("Test program to verify DCAE https connectivity"); + + //Get configuration + DcaeConfig configuration = DcaeConfig.getDefaultConfiguration(); + + if (configuration != null) { + + //Start services + System.out.println("Configuration: "+configuration); + + DcaeSenderImpl dcaeClient = new DcaeSenderImpl(configuration.getEventReveicerUrl(), configuration.getUserCredentials()); + + if (TESTCOLLECTOR_YES) { + System.out.println("Connect to testclient and send notifications"); + + DcaeMessages dcaeMessages = new DcaeMessages(dcaeClient, "ControllerName", 31, null); + + for (int t=0; t < 2; t++) { + try { + Thread.sleep(1000); //1000 milliseconds is one second. + } catch(InterruptedException ex) { + Thread.currentThread().interrupt(); + } + System.out.println(t+". Send notification and receive answer message"); + System.out.println("Heartbeat message: "+dcaeMessages.postHeartBeat()); + System.out.println("Status of ECOMP Client: "+dcaeClient.getStatusAsString()); + } + + } else { + + System.out.println("Connect to server and receive initial answer."); + System.out.println("Message: "+dcaeClient.testConnectServer()); + + } + + } + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/HttpsClient.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/HttpsClient.java new file mode 100644 index 000000000..6ff18b48f --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/dcaeConnector/test/HttpsClient.java @@ -0,0 +1,304 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.dcaeConnector.test; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; +import java.security.cert.Certificate; +import java.security.cert.X509Certificate; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLPeerUnverifiedException; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.dcaeconnector.impl.DcaeProviderClient; + +public class HttpsClient{ + + private static final MyLogger LOG = MyLogger.getLogger(DcaeProviderClient.class); + + void test() { + + TrustManager tm = new X509TrustManager() { + + @Override + public void checkClientTrusted(X509Certificate[] chain, String authType) + throws java.security.cert.CertificateException { + //do nothing, you're the client + } + + @Override + public void checkServerTrusted(X509Certificate[] chain, String authType) + throws java.security.cert.CertificateException { + /* chain[chain.length -1] is the candidate for the + * root certificate. + * Look it up to see whether it's in your list. + * If not, ask the user for permission to add it. + * If not granted, reject. + * Validate the chain using CertPathValidator and + * your list of trusted roots. + */ + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + //also only relevant for servers + return null; + } + }; + + TrustManager tml[] = new TrustManager[1]; + tml[0] = tm; + + + try { + SSLContext ctx = SSLContext.getInstance("TLS"); + ctx.init(null, tml, null); + @SuppressWarnings("unused") + SSLSocketFactory sslF = ctx.getSocketFactory(); + + } catch (NoSuchAlgorithmException | KeyManagementException e) { + e.printStackTrace(); + } + + + }; + + void setupAllTrustingManager() { + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ + @Override + public X509Certificate[] getAcceptedIssuers(){return null;} + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType){} + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType){} + }}; + + // Install the all-trusting trust manager + try { + SSLContext sc = SSLContext.getInstance("TLS"); + sc.init(null, trustAllCerts, new SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + } catch (Exception e) { + ; + } + } + + void testIt(String https_url, String keyStoreName, String keyStorePassword){ + + LOG.info("Message to: {} begin.", https_url); + + if (https_url.equals("off")) { + LOG.info("Function switched off"); + return; + } + + /* + KeyManagerFactory keyManagerFactory = null; + + try { + KeyStore ks = KeyStore.getInstance("JKS"); + FileInputStream in = new FileInputStream(keyStoreName); + ks.load(in, keyStorePassword.toCharArray()); + + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + FileInputStream in2 = new FileInputStream("etc/eventprovider.cert"); + X509Certificate cert = (X509Certificate)certFactory.generateCertificate(in2); + + KeyStore.Entry newEntry = new KeyStore.TrustedCertificateEntry(cert); + ks.setEntry("someAlias", newEntry, null); + + keyManagerFactory = KeyManagerFactory.getInstance("X509"); + keyManagerFactory.init(ks, "yourKeyStorePassword".toCharArray()); + + } catch (KeyStoreException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } catch (FileNotFoundException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } catch (NoSuchAlgorithmException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } catch (CertificateException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } catch (IOException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } catch (UnrecoverableKeyException e1) { + LOG.info("Exception: {}", e1.getMessage()); + } + + // Create a trust manager that does not validate certificate chains + TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager(){ + @Override + public X509Certificate[] getAcceptedIssuers(){return null;} + @Override + public void checkClientTrusted(X509Certificate[] certs, String authType){} + @Override + public void checkServerTrusted(X509Certificate[] certs, String authType){} + }}; + */ + File file = new File(keyStoreName); + LOG.info("Setup keystore begin "+keyStoreName+" "+keyStorePassword+" Exists: "+file.exists()); + + System.setProperty("javax.net.debug","ssl"); + System.setProperty("javax.net.ssl.keyStoreType", "jks"); + System.setProperty("javax.net.ssl.keyStore", keyStoreName); + System.setProperty("javax.net.ssl.keyStorePassword", keyStorePassword); + + LOG.info("Setup keystore complete"); + + javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier( + (hostname, sslSession) -> { + LOG.info("Hostname check {}", hostname); + return true; + }); + LOG.info("Setup name verifier."); + + try { + /* + SSLContext sslContext = SSLContext.getInstance("TLS"); + sslContext.init(keyManagerFactory.getKeyManagers(), trustAllCerts, null); + SSLContext.setDefault(sslContext); + */ + + URL url = new URL(https_url); + LOG.info("Url object created"); + + HttpsURLConnection con = (HttpsURLConnection)url.openConnection(); + + LOG.info("openConnection"); + + //dumpl all cert info + print_https_cert(con); + + //dump all the content + print_content(con); + + } catch (MalformedURLException e) { + LOG.info("Exception: {}", e.getMessage()); + } catch (IOException e) { + LOG.info("Exception: {}", e.getMessage()); + } + + LOG.info("Message to: {} end.", https_url); + + } + + private void print_https_cert(HttpsURLConnection con){ + + StringBuffer logMsg = new StringBuffer(); + + if(con!=null){ + + try { + logMsg.append("Response Code : " + con.getResponseCode()); + logMsg.append("Cipher Suite : " + con.getCipherSuite()); + logMsg.append("\n"); + + Certificate[] certs = con.getServerCertificates(); + for(Certificate cert : certs){ + logMsg.append("Cert Type : " + cert.getType()); + logMsg.append("Cert Hash Code : " + cert.hashCode()); + logMsg.append("Cert Public Key Algorithm : " + cert.getPublicKey().getAlgorithm()); + logMsg.append("Cert Public Key Format : " + cert.getPublicKey().getFormat()); + logMsg.append("\n"); + } + + + } catch (SSLPeerUnverifiedException e) { + logMsg.append(e.getMessage()); + } catch (IOException e){ + logMsg.append(e.getMessage()); + } + } else { + logMsg.append("No connection"); + } + + LOG.info(logMsg.toString()); + } + + private void print_content(HttpsURLConnection con){ + + StringBuffer logMsg = new StringBuffer(); + if(con!=null){ + + try { + + + logMsg.append("****** Content of the URL ********"); + BufferedReader br = + new BufferedReader( + new InputStreamReader(con.getInputStream())); + + String input; + + while ((input = br.readLine()) != null){ + logMsg.append(input); + } + br.close(); + + + } catch (IOException e) { + logMsg.append(e.getMessage()); + } + + } else { + logMsg.append("No connection"); + } + + LOG.info(logMsg.toString()); + + } + + private static class MyLogger { + + private void out( String s, Object...oList) { + StringBuffer sb = new StringBuffer(); + sb.append("-------> "); + sb.append(s); + sb.append(" P: "); + int t = 0; + for (Object o: oList) { + sb.append("["); + sb.append(t++); + sb.append("]("); + sb.append(o.toString()); + sb.append(")"); + } + System.out.println(sb.toString()); + } + + void info( String s, Object...o) { + out(s,o); + } + + static MyLogger getLogger(Class<?> c) { + return new MyLogger(); + } + } +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/Test1dm.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/Test1dm.java new file mode 100644 index 000000000..358a17c39 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/Test1dm.java @@ -0,0 +1,175 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerService.Action; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.DataBrokerNetconfMock; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointMock; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.MountPointServiceMock; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.NotificationPublishServiceMock; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock.RpcProviderRegistryMock; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; + +public class Test1dm { + + private static int DATABASETIMEOUTSECONDS = 30; + + private static Path KARAF_ETC = Paths.get("etc"); + private static DeviceManagerImpl deviceManager; + private static MountPointMock mountPoint; + + + @BeforeClass + public static void before() throws InterruptedException, IOException { + + // Call System property to get the classpath value + Path etc = KARAF_ETC; + delete(etc); + System.out.println("Create empty:"+etc.toString()); + Files.createDirectories(etc); + + //Create mocks + DataBroker dataBroker = new DataBrokerNetconfMock(); + MountPointService mountPointService = new MountPointServiceMock(mountPoint = new MountPointMock()); + NotificationPublishService notificationPublishService = new NotificationPublishServiceMock(); + RpcProviderRegistry rpcProviderRegistry = new RpcProviderRegistryMock(); + + //start using blueprint interface + deviceManager = new DeviceManagerImpl(); + + deviceManager.setDataBroker(dataBroker); + deviceManager.setMountPointService(mountPointService); + deviceManager.setNotificationPublishService(notificationPublishService); + deviceManager.setRpcProviderRegistry(rpcProviderRegistry); + + try { + deviceManager.init(); + } catch (Exception e) { + e.printStackTrace(); + } + System.out.println("Initialization status: "+deviceManager.isDevicemanagerInitializationOk()); + assertTrue("Devicemanager not initialized", deviceManager.isDevicemanagerInitializationOk()); + System.out.println("Initialization done"); + } + + @AfterClass + public static void after() throws InterruptedException, IOException { + + System.out.println("Start shutdown"); + //close using blueprint interface + try { + deviceManager.close(); + } catch (Exception e) { + System.out.println(e); + } + delete(KARAF_ETC); + + } + + @Test + public void test1() throws InterruptedException { + + System.out.println("Test1: Wait for database"); + int timeout = DATABASETIMEOUTSECONDS; + while ( !deviceManager.isDatabaseInitializationFinished() && timeout-- > 0) { + System.out.println("Test1: "+timeout); + Thread.sleep(1000); //On second + } + System.out.println("Test1: database initialized"); + } + + @Test + public void test2() { + System.out.println("Test2: slave mountpoint"); + + mountPoint.setDatabrokerAbsent(true); + NodeId nodeId = new NodeId("mountpointTest1"); + NetconfNodeBuilder nNodeBuilder = new NetconfNodeBuilder(); + + System.out.println("Call devicemanager"); + try { + deviceManager.startListenerOnNodeForConnectedState(Action.ADD, nodeId, nNodeBuilder.build()); + } catch (Exception e) { + e.printStackTrace(); + fail("Exception received."); + } + System.out.println("Test2: Done"); + + } + + @Test + public void test3() { + System.out.println("Test3: master mountpoint"); + + mountPoint.setDatabrokerAbsent(false); + NodeId nodeId = new NodeId("mountpointTest2"); + NetconfNodeBuilder nNodeBuilder = new NetconfNodeBuilder(); + + System.out.println("Call devicemanager"); + + try { + deviceManager.startListenerOnNodeForConnectedState(Action.ADD, nodeId, nNodeBuilder.build()); + } catch (Exception e) { + e.printStackTrace(); + fail("Exception received."); + } + System.out.println("Test3: Done"); + + } + + //********************* Private + + private static void delete(Path etc) throws IOException { + if (Files.exists(etc)) { + System.out.println("Found and remove:"+etc.toString()); + delete(etc.toFile()); + } + } + + private static void delete(File f) throws IOException { + if (f.isDirectory()) { + for (File c : f.listFiles()) { + delete(c); + } + } + if (!f.delete()) { + throw new FileNotFoundException("Failed to delete file: " + f); + } + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestMapper.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestMapper.java new file mode 100644 index 000000000..4166101c4 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/TestMapper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.onap.ccsdk.features.sdnr.wt.devicemanager.test; + +import org.junit.Test; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.database.HtMapper; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.performancemanager.impl.database.types.EsHistoricalPerformance15Minutes; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime; +import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.LayerProtocolName; +import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.UniversalId; +import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.Lp; +import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.logical.termination.point.g.LpBuilder; +import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev181010.air._interface.historical.performances.g.HistoricalPerformanceDataListBuilder; + +public class TestMapper { + + @Test + public void test() { + + int t = 0; + System.out.println(t++); + + HtMapper<EsHistoricalPerformance15Minutes> mapper = new HtMapper<>(EsHistoricalPerformance15Minutes.class); + System.out.println(t++); + + + Lp layerProtocol = new LpBuilder().setUuid(new UniversalId("TestId")).setLayerProtocolName(new LayerProtocolName("LayprotcolTest")).build(); + System.out.println(t++); + EsHistoricalPerformance15Minutes pmData = new EsHistoricalPerformance15Minutes("Testnode", layerProtocol); + System.out.println(t++); + + //AirInterfaceHistoricalPerformancesBuilder builder1 = new AirInterfaceHistoricalPerformancesBuilder(); + //System.out.println(t++); + + + HistoricalPerformanceDataListBuilder builder2 = new HistoricalPerformanceDataListBuilder(); + System.out.println(t++); + builder2.setPeriodEndTime(new DateAndTime("2019-06-06T12:12:12.1Z")); + System.out.println(t++); + + String json = mapper.objectToJson(pmData); + + System.out.println("Result: "+pmData); + System.out.println("Result: "+json); + + //fail("Not yet implemented"); + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerMountpointMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerMountpointMock.java new file mode 100644 index 000000000..09e0db7d1 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerMountpointMock.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import org.opendaylight.controller.md.sal.binding.api.BindingService; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class DataBrokerMountpointMock implements DataBroker, BindingService { + + @Override + public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener( + DataTreeIdentifier<T> arg0, L arg1) { + return null; + } + + @Override + public BindingTransactionChain createTransactionChain(TransactionChainListener listener) { + return null; + } + + @Override + public ReadOnlyTransaction newReadOnlyTransaction() { + return null; + } + + @Override + public ReadWriteTransaction newReadWriteTransaction() { + return null; + } + + @Override + public WriteTransaction newWriteOnlyTransaction() { + return null; + } + + @Override + public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType store, + InstanceIdentifier<?> path, DataChangeListener listener, DataChangeScope triggeringScope) { + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerNetconfMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerNetconfMock.java new file mode 100644 index 000000000..77ee58729 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/DataBrokerNetconfMock.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; +import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class DataBrokerNetconfMock implements DataBroker { + + @Override + public <T extends DataObject, L extends DataTreeChangeListener<T>> ListenerRegistration<L> registerDataTreeChangeListener( + DataTreeIdentifier<T> arg0, L arg1) { + // TODO Auto-generated method stub + return null; + } + + @Override + public BindingTransactionChain createTransactionChain(TransactionChainListener listener) { + // TODO Auto-generated method stub + return null; + } + + @Override + public ReadOnlyTransaction newReadOnlyTransaction() { + return new ReadOnlyTransactionMock(); + } + + @Override + public ReadWriteTransaction newReadWriteTransaction() { + // TODO Auto-generated method stub + return null; + } + + @Override + public WriteTransaction newWriteOnlyTransaction() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ListenerRegistration<DataChangeListener> registerDataChangeListener(LogicalDatastoreType store, + InstanceIdentifier<?> path, DataChangeListener listener, DataChangeScope triggeringScope) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointMock.java new file mode 100644 index 000000000..ca63dcf71 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointMock.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import com.google.common.base.Optional; +import org.opendaylight.controller.md.sal.binding.api.BindingService; +import org.opendaylight.controller.md.sal.binding.api.MountPoint; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +public class MountPointMock implements MountPoint { + + private boolean databrokerAbsent = true; + private final DataBrokerMountpointMock dataBroker = new DataBrokerMountpointMock(); + + @Override + public InstanceIdentifier<?> getIdentifier() { + return null; + } + + @SuppressWarnings("unchecked") + @Override + public <T extends BindingService> Optional<T> getService(Class<T> service) { + + System.out.println("Requested mountpoint service: "+service.getSimpleName()+" databrokerAbsent state: "+databrokerAbsent); + + Optional<?> res = Optional.absent(); + if (service.isInstance(dataBroker)) { + res = databrokerAbsent ? Optional.absent() : Optional.of(dataBroker); + } else if (service.isInstance(org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry.class)) { + res = Optional.of(new RpcConsumerRegistryMock()); + } + return (Optional<T>)res; + } + + public void setDatabrokerAbsent( boolean state) { + this.databrokerAbsent = state; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointServiceMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointServiceMock.java new file mode 100644 index 000000000..797ccb286 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/MountPointServiceMock.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import com.google.common.base.Optional; +import org.opendaylight.controller.md.sal.binding.api.MountPoint; +import org.opendaylight.controller.md.sal.binding.api.MountPointService; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +public class MountPointServiceMock implements MountPointService { + + private final MountPointMock mountpoint; + + public MountPointServiceMock(MountPointMock mountpoint) { + this.mountpoint = mountpoint; + } + + @Override + public Optional<MountPoint> getMountPoint(InstanceIdentifier<?> mountPoint) { + + Optional<MountPoint> optional = Optional.of(mountpoint); + return optional; + } + + @Override + public <T extends MountPointListener> ListenerRegistration<T> registerListener(InstanceIdentifier<?> path, + T listener) { + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/NotificationPublishServiceMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/NotificationPublishServiceMock.java new file mode 100644 index 000000000..54408c451 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/NotificationPublishServiceMock.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import com.google.common.util.concurrent.ListenableFuture; +import java.util.concurrent.TimeUnit; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.yangtools.yang.binding.Notification; + +/** + * @author herbert + * + */ +public class NotificationPublishServiceMock implements NotificationPublishService { + + /* (non-Javadoc) + * @see org.opendaylight.controller.md.sal.binding.api.NotificationPublishService#offerNotification(org.opendaylight.yangtools.yang.binding.Notification) + */ + @Override + public ListenableFuture<?> offerNotification(Notification notification) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.opendaylight.controller.md.sal.binding.api.NotificationPublishService#offerNotification(org.opendaylight.yangtools.yang.binding.Notification, int, java.util.concurrent.TimeUnit) + */ + @Override + public ListenableFuture<?> offerNotification(Notification notification, int timeout, TimeUnit unit) + throws InterruptedException { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.opendaylight.controller.md.sal.binding.api.NotificationPublishService#putNotification(org.opendaylight.yangtools.yang.binding.Notification) + */ + @Override + public void putNotification(Notification notification) throws InterruptedException { + // TODO Auto-generated method stub + + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ReadOnlyTransactionMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ReadOnlyTransactionMock.java new file mode 100644 index 000000000..0bfe4b3eb --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/ReadOnlyTransactionMock.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Executor; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.netconf.wrapperc.WrapperMicrowaveModelRev181010; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.AvailableCapabilitiesBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapability; +import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.netconf.node.connection.status.available.capabilities.AvailableCapabilityBuilder; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; +import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * @author herbert + * + */ +@SuppressWarnings("deprecation") +public class ReadOnlyTransactionMock implements ReadOnlyTransaction { + + + @Override + public Object getIdentifier() { + return null; + } + + @Override + public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store, + InstanceIdentifier<T> path) { + + NetconfNodeBuilder netconfNodeBuilder = new NetconfNodeBuilder(); + netconfNodeBuilder.setConnectionStatus(ConnectionStatus.Connected); + netconfNodeBuilder.setAvailableCapabilities(getCababilitiesList(WrapperMicrowaveModelRev181010.QNAME.toString()).build()); + NetconfNode nnode = netconfNodeBuilder.build(); + NodeBuilder nodeBuilder = new NodeBuilder(); + nodeBuilder.addAugmentation(NetconfNode.class, nnode); + Node node = nodeBuilder.build(); + @SuppressWarnings("unchecked") + Optional<T> res1 = (Optional<T>) Optional.of(node); + CheckedFuture<Optional<T>, ReadFailedException> res = new CheckedFuture<Optional<T>, ReadFailedException>() { + + @Override + public void addListener(Runnable arg0, Executor arg1) { + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + return false; + } + + @Override + public Optional<T> get() throws InterruptedException, ExecutionException { + return null; + } + + @Override + public Optional<T> get(long timeout, TimeUnit unit) + throws InterruptedException, ExecutionException, TimeoutException { + return null; + } + + @Override + public boolean isCancelled() { + return false; + } + + @Override + public boolean isDone() { + return false; + } + + @Override + public Optional<T> checkedGet() throws ReadFailedException { + return res1; + } + + @Override + public Optional<T> checkedGet(long arg0, TimeUnit arg1) throws TimeoutException, ReadFailedException { + return null; + } + + }; + + + return res; + } + + private AvailableCapabilitiesBuilder getCababilitiesList(String ... strings) { + return getCababilitiesList(null, strings); + } + + private AvailableCapabilitiesBuilder getCababilitiesList(AvailableCapabilitiesBuilder valueBuilder, String ... strings) { + if (valueBuilder == null) { + valueBuilder = new AvailableCapabilitiesBuilder(); + } + List<AvailableCapability> capabilites = new ArrayList<>(); + for (String s : strings) { + AvailableCapabilityBuilder capabilityBuilder = new AvailableCapabilityBuilder(); + capabilityBuilder.setCapability(s); + capabilites.add(capabilityBuilder.build()); + } + valueBuilder.setAvailableCapability(capabilites); + return valueBuilder; + } + + @Override + public void close() { + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcConsumerRegistryMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcConsumerRegistryMock.java new file mode 100644 index 000000000..5cac97742 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcConsumerRegistryMock.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; +import org.opendaylight.yangtools.yang.binding.RpcService; + +/** + * @author herbert + * + */ +public class RpcConsumerRegistryMock implements RpcConsumerRegistry { + + @Override + public <T extends RpcService> T getRpcService(Class<T> serviceInterface) { + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcProviderRegistryMock.java b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcProviderRegistryMock.java new file mode 100644 index 000000000..831d5ae75 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/java/org/onap/ccsdk/features/sdnr/wt/devicemanager/test/mock/RpcProviderRegistryMock.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * ONAP : ccsdk feature sdnr wt + * ================================================================================ + * Copyright (C) 2019 highstreet technologies GmbH 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.ccsdk.features.sdnr.wt.devicemanager.test.mock; + +import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; +import org.opendaylight.yangtools.concepts.ListenerRegistration; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.binding.RpcService; + +public class RpcProviderRegistryMock implements RpcProviderRegistry { + + @Override + public <T extends RpcService> T getRpcService(Class<T> serviceInterface) { + return null; + } + + @Override + public <L extends RouteChangeListener<RpcContextIdentifier, InstanceIdentifier<?>>> ListenerRegistration<L> registerRouteChangeListener( + L listener) { + return null; + } + + + @Override + public <T extends RpcService> RoutedRpcRegistration<T> addRoutedRpcImplementation(Class<T> serviceInterface, + T implementation) throws IllegalStateException { + return null; + } + + @Override + public <T extends RpcService> RpcRegistration<T> addRpcImplementation(Class<T> serviceInterface, T implementation) + throws IllegalStateException { + System.out.println("Register class "+serviceInterface); + return null; + } + +} diff --git a/sdnr/wt/devicemanager/provider/src/test/resources/aaiclient.properties b/sdnr/wt/devicemanager/provider/src/test/resources/aaiclient.properties new file mode 100644 index 000000000..3e4da05b0 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/resources/aaiclient.properties @@ -0,0 +1,165 @@ +###
+
+# ============LICENSE_START=======================================================
+
+# openECOMP : SDN-C
+
+# ================================================================================
+
+# Copyright (C) 2017 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=========================================================
+
+###
+
+
+
+#
+
+# Configuration file for A&AI Client
+
+#
+
+
+
+#
+
+# Certificate keystore and truststore
+
+#
+
+org.onap.ccsdk.sli.adaptors.aai.ssl.trust=/opt/logs/externals/data/stores/truststore.client.jks
+
+org.onap.ccsdk.sli.adaptors.aai.ssl.trust.psswd=adminadmin
+
+
+
+org.onap.ccsdk.sli.adaptors.aai.ssl.key=/opt/logs/externals/data/stores/keystore.client.p12
+
+org.onap.ccsdk.sli.adaptors.aai.ssl.key.psswd=adminadmin
+
+org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=true
+
+
+
+org.onap.ccsdk.sli.adaptors.aai.application=SDNC
+
+
+
+#org.onap.ccsdk.sli.adaptors.aai.uri=https://aai-int1.test.att.com:8443
+
+org.onap.ccsdk.sli.adaptors.aai.uri=https://aai-pwt3.ecomp.cci.att.com:8443
+
+
+
+connection.timeout=60000
+
+read.timeout=60000
+
+
+
+# query
+
+org.onap.ccsdk.sli.adaptors.aai.path.query=/aai/v13/search/sdn-zone-query
+
+org.onap.ccsdk.sli.adaptors.aai.query.nodes=/aai/v13/search/nodes-query?search-node-type={node-type}&filter={entity-identifier}:EQUALS:{entity-name}
+
+org.onap.ccsdk.sli.adaptors.aai.query.generic=/aai/v13/search/generic-query?key={identifier}:{value}&start-node-type={start-node-type}&include=complex&depth=3
+
+
+
+# named query
+
+org.onap.ccsdk.sli.adaptors.aai.query.named=/aai/search/named-query
+
+
+
+#update
+
+org.onap.ccsdk.sli.adaptors.aai.update=/aai/v13/actions/update
+
+
+
+# UBB Notify
+
+org.onap.ccsdk.sli.adaptors.aai.path.notify=/aai/v13/actions/notify
+
+org.onap.ccsdk.sli.adaptors.aai.notify.selflink.fqdn=/restconf/config/L3SDN-API:services/layer3-service-list/{service-instance-id}
+
+org.onap.ccsdk.sli.adaptors.aai.notify.selflink.avpn=/restconf/config/L3AVPN-EVC-API:services/service-list/{service-instance-id}/service-data/avpn-logicalchannel-information
+
+
+
+# P-Interfaces
+
+org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterfaces=/aai/v13/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces
+
+org.onap.ccsdk.sli.adaptors.aai.path.pserver.pinterface=/aai/v13/cloud-infrastructure/pservers/pserver/{hostname}/p-interfaces/p-interface/{interface-name}
+
+
+
+# VNF IMAGES
+
+org.onap.ccsdk.sli.adaptors.aai.path.vnf.images=/aai/v13/service-design-and-creation/vnf-images
+
+org.onap.ccsdk.sli.adaptors.aai.path.vnf.image=/aai/v13/service-design-and-creation/vnf-images/vnf-image/{att-uuid}
+
+org.onap.ccsdk.sli.adaptors.aai.path.vnf.image.query=/aai/v13/service-design-and-creation/vnf-images/vnf-image?application={application_model}&application-vendor={application_vendor}
+
+
+
+# service instance
+
+org.onap.ccsdk.sli.adaptors.aai.path.svcinst.query=/aai/v13/search/generic-query?key=service-instance.service-instance-id:{svc-instance-id}&start-node-type=service-instance&include=service-instance
+
+org.onap.ccsdk.sli.adaptors.aai.path.service.instance=/aai/v13/business/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}
+
+
+
+# VNF IMAGES QUERY
+
+org.onap.ccsdk.sli.adaptors.aai.path.vnf.image.query=/aai/v13/service-design-and-creation/vnf-images/vnf-image?application={application_model}&application-vendor={application_vendor}
+
+
+
+#
+
+# Formatting
+
+#
+
+org.onap.ccsdk.sli.adaptors.aai.param.format=filter=%s:%s
+
+org.onap.ccsdk.sli.adaptors.aai.param.vnf_type=vnf-type
+
+org.onap.ccsdk.sli.adaptors.aai.param.physical.location.id=physical-location-id
+
+org.onap.ccsdk.sli.adaptors.aai.param.service.type=service-type
+
+
\ No newline at end of file diff --git a/sdnr/wt/devicemanager/provider/src/test/resources/test.properties b/sdnr/wt/devicemanager/provider/src/test/resources/test.properties new file mode 100644 index 000000000..943c25bd9 --- /dev/null +++ b/sdnr/wt/devicemanager/provider/src/test/resources/test.properties @@ -0,0 +1,47 @@ +[dcae] +dcaeUserCredentials=admin:admin +dcaeUrl=off +dcaeHeartbeatPeriodSeconds=120 +dcaeTestCollector=no + +[aots] +userPassword=passwd +soapurladd=off +soapaddtimeout=10 +soapinqtimeout=20 +userName=user +inqtemplate=inqreq.tmpl.xml +assignedto=userid +addtemplate=addreq.tmpl.xml +severitypassthrough=critical,major,minor,warning +systemuser=user +prt-offset=1200 +soapurlinq=off +#smtpHost= +#smtpPort= +#smtpUsername= +#smtpPassword= +#smtpSender= +#smtpReceivers= + +[es] +esCluster=sendateodl5 + +[aai] +#keep comment +aaiHeaders=["X-TransactionId: 9999"] +aaiUrl=http://localhost:81 +aaiUserCredentials=AAI:AAI +aaiDeleteOnMountpointRemove=false +aaiTrustAllCerts=false +aaiApiVersion=aai/v13 +aaiPropertiesFile=aaiclient.properties +aaiApplicationId=SDNR +aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12 +aaiPcks12ClientCertPassphrase=adminadmin +aaiClientConnectionTimeout=30000 + +[pm] +pmCluster=sendateodl5 +pmEnabled=true + |