diff options
author | lizi00164331 <li.zi30@zte.com.cn> | 2017-08-07 11:04:17 +0800 |
---|---|---|
committer | lizi00164331 <li.zi30@zte.com.cn> | 2017-08-07 11:04:17 +0800 |
commit | aba957d99b0d0d21c77d80efe98a3450b6635c1a (patch) | |
tree | e8a5991c966560232d6215831ffe08324f5ff6a3 /esr-core/esr-mgr/src/test | |
parent | 4bcebdf6c7a3cf81a77e1f2931db6d596923b866 (diff) |
Upload the ESR server seed code.
Issue-ID: AAI-67
Change-Id: Ie21ae7baebbb2ea8a35d8b51f75b7e21bcb78671
Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
Diffstat (limited to 'esr-core/esr-mgr/src/test')
13 files changed, 1255 insertions, 0 deletions
diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/CommonManagerTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/CommonManagerTest.java new file mode 100644 index 0000000..fbfc47b --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/CommonManagerTest.java @@ -0,0 +1,138 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.resource; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.esr.dao.DaoManager; +import org.onap.aai.esr.db.util.H2DbServer; +import org.onap.aai.esr.db.util.HibernateSession; +import org.onap.aai.esr.entity.db.BaseData; +import org.onap.aai.esr.entity.db.EmsData; +import org.onap.aai.esr.entity.db.VnfmData; +import org.onap.aai.esr.exception.ExtsysException; +import org.onap.aai.esr.handle.CommonHandler; +import org.onap.aai.esr.handle.EmsHandler; +import org.onap.aai.esr.handle.VnfmHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.HashMap; +import java.util.List; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EmsHandler.class, VnfmHandler.class}) +public class CommonManagerTest { + private CommonHandler handler = new CommonHandler(); + private EmsHandler emshandler; + private VnfmHandler vnfHandler; + private HashMap<String, String> idMap = new HashMap<String, String>(); + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + + } + + /** + * shut down db. + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * init db data. + */ + @Before + public void setUp() throws Exception { + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + try { + EmsData data = new EmsData(); + data.setName("ems"); + emshandler = PowerMockito.spy(new EmsHandler()); + PowerMockito.doReturn(true).when(emshandler, "validity", data); + idMap.put("ems", emshandler.add(data).getId()); + VnfmData vnfm = new VnfmData(); + vnfm.setName("VNFM"); + vnfHandler = PowerMockito.spy(new VnfmHandler()); + PowerMockito.doReturn(true).when(vnfHandler, "validity", vnfm); + idMap.put("vnfm", vnfHandler.add(vnfm).getId()); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * clear db data. + */ + @After + public void tearDown() { + try { + java.util.Iterator<String> it = idMap.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + if ("ems".equals(key)) { + emshandler.delete(idMap.get(key)); + } else { + vnfHandler.delete(idMap.get(key)); + } + } + + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + @Test + public void testQueryEmsById_exist() { + List<BaseData> emslist = null; + List<BaseData> vnfmlist = null; + try { + emslist = handler.getInstanceById(idMap.get("ems")); + vnfmlist = handler.getInstanceById(idMap.get("vnfm")); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(emslist.size() > 0 && vnfmlist.size() > 0); + } + + @Test + public void testQueryEmsById_not_exist() { + List<BaseData> list = null; + try { + list = handler.getInstanceById("123456"); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() == 0); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/EmsManagerTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/EmsManagerTest.java new file mode 100644 index 0000000..05d1c45 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/EmsManagerTest.java @@ -0,0 +1,166 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.resource; + +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.esr.dao.DaoManager; +import org.onap.aai.esr.db.util.H2DbServer; +import org.onap.aai.esr.db.util.HibernateSession; +import org.onap.aai.esr.entity.db.EmsData; +import org.onap.aai.esr.exception.ExtsysException; +import org.onap.aai.esr.handle.EmsHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.List; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({EmsHandler.class}) +public class EmsManagerTest { + private EmsHandler handler; + private static String id = "0000000000000000"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + + } + + /** + * shut down db. + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * init db data. + */ + @Before + public void setUp() throws Exception { + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + EmsData data = new EmsData(); + data.setName("ems"); + handler = PowerMockito.spy(new EmsHandler()); + PowerMockito.doReturn(true).when(handler, "validity", data); + try { + id = handler.add(data).getId(); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * clear db data. + */ + @After + public void tearDown() { + try { + handler.delete(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + @Test + public void testQueryEmsById_exist() { + List<EmsData> list = null; + try { + list = handler.getEmsById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testAddEmsInstance_validity_false() throws Exception { + EmsData data = new EmsData(); + data.setName("ems2"); + PowerMockito.doReturn(false).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testAddEmsInstance_validity_throw_ExtsysException() throws Exception { + EmsData data = new EmsData(); + data.setName("ems2"); + PowerMockito.doReturn(false).when(handler, "validity", data); + PowerMockito.doThrow(new ExtsysException()).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testQueryEmsById_not_exist() { + List<EmsData> list = null; + try { + list = handler.getEmsById("123456"); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testUpdateEms() { + EmsData data = new EmsData(); + data.setName("ems_new"); + try { + handler.update(data, id); + } catch (ExtsysException error1) { + Assert.fail("Exception" + error1.getMessage()); + return; + } + List<EmsData> list = null; + try { + list = handler.getEmsById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + assertTrue(list.size() > 0 && list.get(0).getName().equals("ems_new")); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/SdncManagerTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/SdncManagerTest.java new file mode 100644 index 0000000..ab91584 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/SdncManagerTest.java @@ -0,0 +1,165 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.resource; + +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.esr.dao.DaoManager; +import org.onap.aai.esr.db.util.H2DbServer; +import org.onap.aai.esr.db.util.HibernateSession; +import org.onap.aai.esr.entity.db.SdncData; +import org.onap.aai.esr.exception.ExtsysException; +import org.onap.aai.esr.handle.SdncHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.util.List; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SdncHandler.class}) +public class SdncManagerTest { + private SdncHandler handler; + private String id = "0000000000000000"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + } + + /** + * shut down db. + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * init db data. + */ + @Before + public void setUp() throws Exception { + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + SdncData data = new SdncData(); + data.setName("sdnc"); + handler = PowerMockito.spy(new SdncHandler()); + PowerMockito.doReturn(true).when(handler, "validity", data); + try { + id = handler.add(data).getId(); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * clear db data. + */ + @After + public void tearDown() { + try { + handler.delete(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + @Test + public void testAddSdncInstance_validity_false() throws Exception { + SdncData data = new SdncData(); + data.setName("sdnc"); + PowerMockito.doReturn(false).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testAddSdncInstance_validity_throw_ExtsysException() throws Exception { + SdncData data = new SdncData(); + data.setName("ems2"); + PowerMockito.doReturn(false).when(handler, "validity", data); + PowerMockito.doThrow(new ExtsysException()).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testQuerySdncById_exist() { + List<SdncData> list = null; + try { + list = handler.getSdncById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQuerySdncById_not_exist() { + List<SdncData> list = null; + try { + list = handler.getSdncById("100001"); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testUpdateSdnc() { + SdncData data = new SdncData(); + data.setName("Sdnc_new"); + try { + handler.update(data, id); + } catch (ExtsysException error1) { + Assert.fail("Exception" + error1.getMessage()); + return; + } + List<SdncData> list = null; + try { + list = handler.getSdncById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + assertTrue(list.size() > 0 && list.get(0).getName().equals("Sdnc_new")); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VimManagerTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VimManagerTest.java new file mode 100644 index 0000000..c208181 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VimManagerTest.java @@ -0,0 +1,168 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.resource; + +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.esr.dao.DaoManager; +import org.onap.aai.esr.db.util.H2DbServer; +import org.onap.aai.esr.db.util.HibernateSession; +import org.onap.aai.esr.entity.db.VimData; +import org.onap.aai.esr.exception.ExtsysException; +import org.onap.aai.esr.handle.VimHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +import java.util.List; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({VimHandler.class}) +public class VimManagerTest { + private VimHandler handler; + private String id = "0000000000000000"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + + } + + /** + * shut down db. + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * init db data. + */ + @Before + public void setUp() throws Exception { + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + VimData data = new VimData(); + handler = PowerMockito.spy(new VimHandler()); + PowerMockito.doReturn(true).when(handler, "validity", data); + data.setId("10000"); + data.setName("vim"); + try { + id = handler.add(data).getId(); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * clear db data. + */ + @After + public void tearDown() { + try { + handler.delete(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + @Test + public void testAddVimInstance_validity_false() throws Exception { + VimData data = new VimData(); + data.setName("Vim"); + PowerMockito.doReturn(false).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testAddVimInstance_validity_throw_ExtsysException() throws Exception { + VimData data = new VimData(); + data.setName("vim2"); + PowerMockito.doReturn(false).when(handler, "validity", data); + PowerMockito.doThrow(new ExtsysException()).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testQueryVimById_exist() { + List<VimData> list = null; + try { + list = handler.getVimById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryVimById_not_exist() { + List<VimData> list = null; + try { + list = handler.getVimById("100001"); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testUpdateVim() { + VimData data = new VimData(); + data.setName("vim_new"); + try { + handler.update(data, id); + } catch (ExtsysException error1) { + Assert.fail("Exception" + error1.getMessage()); + return; + } + List<VimData> list = null; + try { + list = handler.getVimById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + assertTrue(list.size() > 0 && list.get(0).getName().equals("vim_new")); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VnfmManagerTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VnfmManagerTest.java new file mode 100644 index 0000000..e4e8b9e --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/resource/VnfmManagerTest.java @@ -0,0 +1,166 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.resource; + +import static org.junit.Assert.assertTrue; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.esr.dao.DaoManager; +import org.onap.aai.esr.db.util.H2DbServer; +import org.onap.aai.esr.db.util.HibernateSession; +import org.onap.aai.esr.entity.db.VnfmData; +import org.onap.aai.esr.exception.ExtsysException; +import org.onap.aai.esr.handle.VnfmHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + + +import java.util.List; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({VnfmHandler.class}) +public class VnfmManagerTest { + private VnfmHandler handler; + private String id = "0000000000000000"; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + } + + /** + * shut down db. + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * init db data. + */ + @Before + public void setUp() throws Exception { + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + VnfmData data = new VnfmData(); + data.setName("vnfm"); + handler = PowerMockito.spy(new VnfmHandler()); + PowerMockito.doReturn(true).when(handler, "validity", data); + try { + id = handler.add(data).getId(); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + /** + * clear db data. + */ + @After + public void tearDown() { + try { + handler.delete(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + } + } + + + @Test + public void testQueryVnfmById_exist() { + List<VnfmData> list = null; + try { + list = handler.getVnfmById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryVnfmById_not_exist() { + List<VnfmData> list = null; + try { + list = handler.getVnfmById("100001"); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testUpdateVnfm() { + VnfmData data = new VnfmData(); + data.setName("vnfm_new"); + try { + handler.update(data, id); + } catch (ExtsysException error1) { + Assert.fail("Exception" + error1.getMessage()); + return; + } + List<VnfmData> list = null; + try { + list = handler.getVnfmById(id); + } catch (ExtsysException error) { + Assert.fail("Exception" + error.getMessage()); + return; + } + assertTrue(list.size() > 0 && list.get(0).getName().equals("vnfm_new")); + } + + @Test + public void testAddVnfmInstance_validity_false() throws Exception { + VnfmData data = new VnfmData(); + data.setName("Vnfm"); + PowerMockito.doReturn(false).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } + + @Test + public void testAddVnfmInstance_validity_throw_ExtsysException() throws Exception { + VnfmData data = new VnfmData(); + data.setName("vnfm2"); + PowerMockito.doReturn(false).when(handler, "validity", data); + PowerMockito.doThrow(new ExtsysException()).when(handler, "validity", data); + try { + handler.add(data); + } catch (ExtsysException error) { + Assert.assertTrue(true); + return; + } + Assert.fail("not Exception"); + } +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/CatalogDbUtilTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/CatalogDbUtilTest.java new file mode 100644 index 0000000..4080c26 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/CatalogDbUtilTest.java @@ -0,0 +1,60 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.aai.esr.util.ExtsysDbUtil; + +public class CatalogDbUtilTest { + + @Test + public void when_generate_id_is_not_null() { + String actualUuid = ExtsysDbUtil.generateId(); + assertNotNull(actualUuid); + } + + @Test + public void when_input_empty_string_output_false() { + boolean expect = false; + boolean actual = ExtsysDbUtil.isNotEmpty(""); + assertEquals(expect, actual); + } + + @Test + public void when_input_blan_string_output_true() { + boolean expect = true; + boolean actual = ExtsysDbUtil.isNotEmpty(" "); + assertEquals(expect, actual); + } + + @Test + public void when_input_null_string_output_false() { + boolean expect = false; + boolean actual = ExtsysDbUtil.isNotEmpty(null); + assertEquals(expect, actual); + } + + @Test + public void when_input_str_string_output_true() { + boolean expect = true; + boolean actual = ExtsysDbUtil.isNotEmpty("str"); + assertEquals(expect, actual); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServer.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServer.java new file mode 100644 index 0000000..39980cd --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServer.java @@ -0,0 +1,58 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.util; + +import org.h2.tools.Server; + +import java.sql.SQLException; + + +public class H2DbServer { + + private static Server h2DbWebServer; + private static Server h2DbTcpServer; + + /** + * start db. + */ + public static void startUp() { + try { + h2DbWebServer = + Server.createWebServer(new String[] {"-web", "-webAllowOthers", "-webPort", "18208"}); + h2DbWebServer.start(); + + h2DbTcpServer = + Server.createTcpServer(new String[] {"-tcp", "-tcpAllowOthers", "-tcpPort", "18207"}); + h2DbTcpServer.start(); + } catch (SQLException error) { + error.printStackTrace(); + } + } + + /** + * stop db. + */ + public static void shutDown() { + if (h2DbWebServer.isRunning(true)) { + h2DbWebServer.stop(); + h2DbWebServer.shutdown(); + } + if (h2DbTcpServer.isRunning(true)) { + h2DbTcpServer.stop(); + h2DbTcpServer.shutdown(); + } + } +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServerUtil.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServerUtil.java new file mode 100644 index 0000000..8954d67 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/H2DbServerUtil.java @@ -0,0 +1,66 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.util; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.SQLExec; +import org.apache.tools.ant.types.EnumeratedAttribute; + +import java.io.File; +import java.net.URISyntaxException; + + +public class H2DbServerUtil { + private static String resourcePath; + + /** + * init db table. + */ + public static void initTable() { + init(); + SQLExec sqlExec = new SQLExec(); + // set db connetc parameter + sqlExec.setDriver("org.h2.Driver"); + sqlExec.setUrl("jdbc:h2:tcp://localhost:18209/" + resourcePath + "db/extsys"); + sqlExec.setUserid("extsys"); + sqlExec.setPassword("extsys"); + // execute sql + sqlExec.setSrc(new File(resourcePath + "sql/extsys-resource-createObj-mysql.sql")); + sqlExec.setOnerror( + (SQLExec.OnError) (EnumeratedAttribute.getInstance(SQLExec.OnError.class, "abort"))); + sqlExec.setPrint(true); // set print + sqlExec.setProject(new Project()); + sqlExec.execute(); + } + + private static void init() { + try { + resourcePath = HibernateSession.class.getResource("/").toURI().getPath(); + } catch (URISyntaxException error) { + error.printStackTrace(); + } + } + + /** + * init db. + */ + public static void main(String [] args) { + H2DbServer.startUp(); + H2DbServerUtil.initTable(); + H2DbServer.shutDown(); + } + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HibernateSession.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HibernateSession.java new file mode 100644 index 0000000..fd3f36b --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HibernateSession.java @@ -0,0 +1,68 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.util; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; + +import java.io.File; +import java.net.URISyntaxException; + +public class HibernateSession { + private static File cfgfile = null; + + private static ServiceRegistry serviceRegistry = null; + private static Configuration configuration = null; + private static SessionFactory sessionFactory = null; + private static String resourcePath; + + /** + * Get a hibernate sessionFactory. + */ + public static SessionFactory init() { + initConfigure(); + configuration = new Configuration().configure(cfgfile); + configuration.setProperty("hibernate.connection.url", + "jdbc:h2:tcp://localhost:18207/" + resourcePath + "db/extsys"); + serviceRegistry = + new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + return sessionFactory; + } + + private static void initConfigure() { + try { + resourcePath = HibernateSession.class.getResource("/").toURI().getPath(); + } catch (URISyntaxException error) { + error.printStackTrace(); + } + final String filename = "Hibernate.cfg.xml"; + cfgfile = new File(resourcePath + filename); + } + + /** + * Destory a hibernate sessionFactory. + */ + public static void destory() { + if (sessionFactory != null && !sessionFactory.isClosed()) { + sessionFactory.close(); + } + } + + +} diff --git a/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HqlFactoryTest.java b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HqlFactoryTest.java new file mode 100644 index 0000000..e3a40b4 --- /dev/null +++ b/esr-core/esr-mgr/src/test/java/org/onap/aai/esr/db/util/HqlFactoryTest.java @@ -0,0 +1,91 @@ +/** + * Copyright 2016 ZTE Corporation. + * + * 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. + */ +package org.onap.aai.esr.db.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.aai.esr.entity.db.VnfmData; +import org.onap.aai.esr.util.HqlFactory; + + +public class HqlFactoryTest { + + @Test + public void when_input_entity_output_udatehql() { + VnfmData data = new VnfmData(); + String filter = "vnfmId='xd03dsfsdfsfsdfsd'"; + data.setName("csarName"); + data.setType("NS"); + String expect = + "update VnfmData set name='csarName',type='NS' where vnfmId='xd03dsfsdfsfsdfsd'"; + String actual = HqlFactory.getUpdateHql(data, null, filter); + assertEquals(expect, actual); + } + + @Test + public void when_input_null_testContain_output_false() { + boolean expect = false; + boolean actual = HqlFactory.contain(null, "name"); + assertEquals(expect, actual); + String[] src = new String[0]; + actual = HqlFactory.contain(src, "name"); + assertEquals(expect, actual); + src = new String[1]; + actual = HqlFactory.contain(src, null); + assertEquals(expect, actual); + } + + @Test + public void when_input_src_contain_target_testContain_output_true() { + boolean expect = true; + String [] src = {"name", "type"}; + String target = "name"; + boolean actual = HqlFactory.contain(src, target); + assertEquals(expect, actual); + } + + @Test + public void when_input_src_not_contain_target_testContain_output_false() { + boolean expect = false; + String [] src = {"name", "type"}; + String target = "version"; + boolean actual = HqlFactory.contain(src, target); + assertEquals(expect, actual); + } + + @Test + public void testGetOidFilter() { + // fail("Not yet implemented"); + String key = "csarId"; + String value = "xd03dsfsdfsfsdfsd"; + String expect = "csarId= 'xd03dsfsdfsfsdfsd'"; + String actual = HqlFactory.getOidFilter(key, value); + assertEquals(expect, actual); + } + + @Test + public void when_input_entity_output_queryhql() { + VnfmData data = new VnfmData(); + String filter = "vnfmId"; + data.setName("csarName"); + data.setType("NS"); + String expect = "select q.vnfmId from VnfmData as q where q.name='csarName' and q.type='NS'"; + String actual = HqlFactory.getQueryHql(data, filter); + assertEquals(expect, actual); + } + +} diff --git a/esr-core/esr-mgr/src/test/resources/Hibernate.cfg.xml b/esr-core/esr-mgr/src/test/resources/Hibernate.cfg.xml new file mode 100644 index 0000000..8d0776d --- /dev/null +++ b/esr-core/esr-mgr/src/test/resources/Hibernate.cfg.xml @@ -0,0 +1,38 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2016 ZTE Corporation. + + 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. + +--> +<!DOCTYPE hibernate-configuration PUBLIC +"-//Hibernate/Hibernate Configuration DTD 3.0//EN" +"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> +<hibernate-configuration> +<session-factory> + <property name="show_sql">true</property> + <property name="dialect">org.hibernate.dialect.H2Dialect</property> + <property name="hibernate.connection.driver_class">org.h2.Driver</property> + <property name="hibernate.connection.url">jdbc:h2:tcp://localhost:18207/./db/extsys</property> + <property name="hibernate.connection.username">extsys</property> + <property name="hibernate.connection.password">extsys</property> + <property name="hbm2ddl">update</property> + <property name="current_session_context_class">thread</property> + <mapping class="org.onap.aai.esr.entity.db.EmsData"/> + <mapping class="org.onap.aai.esr.entity.db.BaseData"/> + <mapping class="org.onap.aai.esr.entity.db.SdncData"/> + <mapping class="org.onap.aai.esr.entity.db.VimData"/> + <mapping class="org.onap.aai.esr.entity.db.VnfmData"/> +</session-factory> +</hibernate-configuration> diff --git a/esr-core/esr-mgr/src/test/resources/db/extsys.mv.db b/esr-core/esr-mgr/src/test/resources/db/extsys.mv.db Binary files differnew file mode 100644 index 0000000..facfeac --- /dev/null +++ b/esr-core/esr-mgr/src/test/resources/db/extsys.mv.db diff --git a/esr-core/esr-mgr/src/test/resources/sql/extsys-resource-createObj-mysql.sql b/esr-core/esr-mgr/src/test/resources/sql/extsys-resource-createObj-mysql.sql new file mode 100644 index 0000000..073c73f --- /dev/null +++ b/esr-core/esr-mgr/src/test/resources/sql/extsys-resource-createObj-mysql.sql @@ -0,0 +1,71 @@ +-- +-- Copyright 2016 ZTE Corporation. +-- +-- 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. +-- + +DROP TABLE IF EXISTS extsys_base_table; +CREATE TABLE extsys_base_table ( + ID VARCHAR(200) NOT NULL, + NAME VARCHAR(200) NULL, + TYPE VARCHAR(200) NULL, + VENDOR VARCHAR(100) NULL, + VERSION VARCHAR(100) NULL, + DESCRIPTION VARCHAR(100) NULL, + CREATETIME VARCHAR(200) NULL, + CATAGORY VARCHAR(200) NULL, + CONSTRAINT extsys_base_table PRIMARY KEY(ID) +); +DROP TABLE IF EXISTS extsys_ems_table; +CREATE TABLE extsys_ems_table ( + EMSID VARCHAR(200) NOT NULL, + URL VARCHAR(100) NULL, + PRODUCTNAME VARCHAR(100) NULL, + USERNAME VARCHAR(100) NULL, + PASSWORD VARCHAR(100) NULL, + CONSTRAINT extsys_ems_table PRIMARY KEY(EMSID) +); + +DROP TABLE IF EXISTS extsys_sdnc_table; +CREATE TABLE extsys_sdnc_table ( + SDNCONTROLLERID VARCHAR(200) NOT NULL, + URL VARCHAR(100) NULL, + USERNAME VARCHAR(100) NULL, + PASSWORD VARCHAR(100) NULL, + PRODUCTNAME VARCHAR(100) NULL, + PROTOCOL VARCHAR(100) NULL, + CONSTRAINT extsys_sdnc_table PRIMARY KEY(SDNCONTROLLERID) +); + +DROP TABLE IF EXISTS extsys_vim_table; +CREATE TABLE extsys_vim_table ( + VIMID VARCHAR(200) NOT NULL, + URL VARCHAR(100) NULL, + USERNAME VARCHAR(100) NULL, + PASSWORD VARCHAR(100) NULL, + DOMAIN VARCHAR(100) NULL, + TENANT VARCHAR(100) NULL, + CONSTRAINT extsys_vim_table PRIMARY KEY(VIMID) +); + +DROP TABLE IF EXISTS extsys_vnfm_table; +CREATE TABLE extsys_vnfm_table ( + VNFMID VARCHAR(200) NOT NULL, + URL VARCHAR(200) NULL, + USERNAME VARCHAR(100) NULL, + PASSWORD VARCHAR(100) NULL, + VIMID VARCHAR(100) NULL, + CERTIFICATEURL VARCHAR(200) NULL, + CONSTRAINT extsys_vnfm_table PRIMARY KEY(VNFMID) +); + |