diff options
Diffstat (limited to 'catalog-core/catalog-mgr/src/test')
15 files changed, 1585 insertions, 0 deletions
diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/IntegrationManager.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/IntegrationManager.java new file mode 100644 index 00000000..8e212103 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/IntegrationManager.java @@ -0,0 +1,178 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.resource; + +import java.util.ArrayList; + +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.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.dao.DaoManager; +import org.openo.commontosca.catalog.db.entity.NodeTemplateData; +import org.openo.commontosca.catalog.db.entity.PackageData; +import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; +import org.openo.commontosca.catalog.db.entity.TemplateData; +import org.openo.commontosca.catalog.db.util.H2DbServer; +import org.openo.commontosca.catalog.db.util.HibernateSession; + +public class IntegrationManager { + private static PackageManager packageManager; + private static TemplateManager templateManager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + packageManager = PackageManager.getInstance(); + templateManager = TemplateManager.getInstance(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setDaoNull(); + H2DbServer.shutDown(); + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Before + public void setUp() { + initPackageInfo(); + initTemplateInfo(); + } + + public void initPackageInfo() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + data.setName("AG"); + data.setVersion("v1.0"); + data.setProvider("ZTE"); + try { + packageManager.addPackage(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + public void deletePackageInfo() { + try { + packageManager.deletePackage("10001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + public void initTemplateInfo() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + TemplateData data = new TemplateData(); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + serviceData.setCsarId("10001"); + serviceData.setServiceTemplateId("20001"); + serviceData.setVendor("ZTE"); + serviceData.setVersion("v1.0"); + NodeTemplateData nodeData = new NodeTemplateData(); + nodeData.setName("node"); + nodeData.setNodeTemplateId("30001"); + nodeData.setServiceTemplateId("20001"); + nodelist.add(nodeData); + data.setServiceTemplate(serviceData); + data.setNodeTemplates(nodelist); + try { + templateManager.addServiceTemplate(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + public void deleteTemplate() { + try { + templateManager.deleteServiceTemplateById("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @After + public void tearDown() { + deleteTemplate(); + deletePackageInfo(); + } + + @Test + public void testDeletePackageByServiceTemplateId() { + try { + packageManager.deletePackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = packageManager.queryPackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testQueryPackageByServiceTemplateId() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = packageManager.queryPackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testDeleteServiceTemplateByCsarPackageInfo() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + templateManager.deleteServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + try { + list = templateManager.queryServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testQueryServiceTemplateByCsarPackageInfo() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = templateManager.queryServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/PackageManagerTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/PackageManagerTest.java new file mode 100644 index 00000000..52ec701f --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/PackageManagerTest.java @@ -0,0 +1,165 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.resource; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +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.openo.commontosca.catalog.db.common.Parameters; +import org.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.dao.DaoManager; +import org.openo.commontosca.catalog.db.entity.PackageData; +import org.openo.commontosca.catalog.db.util.H2DbServer; +import org.openo.commontosca.catalog.db.util.HibernateSession; + +public class PackageManagerTest { + private static PackageManager manager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + manager = PackageManager.getInstance(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setPackageDao(null); + H2DbServer.shutDown(); + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Before + public void setUp() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + data.setName("AG"); + data.setVersion("v1.0"); + data.setProvider("ZTE"); + try { + manager.addPackage(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @After + public void tearDown() { + try { + manager.deletePackage("10001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testAddPackageRepeat() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + data.setName("AG"); + data.setVersion("v1.0"); + data.setProvider("ZTE"); + try { + manager.addPackage(data); + Assert.fail("no exception"); + } catch (CatalogResourceException e) { + Assert.assertTrue(true); + } + + } + + @Test + public void testQueryPackageByCsarId_exist() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackageByCsarId("10001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryPackageByCsarId_not_exist() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackageByCsarId("10002"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testQueryPackage_exist() { + + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackage("AG", "ZTE", "v1.0", null, null); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + + } + + @Test + public void testQueryPackage_not_exist() { + + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackage("AG", "ZTE", "v2.0", null, null); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() == 0); + + } + + @Test + public void testUpdatePackage() { + PackageData data = new PackageData(); + data.setSize("20M"); + try { + manager.updatePackage(data, "10001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + Map<String, String> queryParam = new HashMap<String, String>(); + queryParam.put(Parameters.csarId.name(), "10001"); + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackageByCsarId("10001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + assertTrue(list.size() > 0 && list.get(0).getSize().equals("20M")); + } + +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateManagerTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateManagerTest.java new file mode 100644 index 00000000..66b25048 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateManagerTest.java @@ -0,0 +1,160 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.resource; + +import java.util.ArrayList; + +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.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.dao.DaoManager; +import org.openo.commontosca.catalog.db.entity.NodeTemplateData; +import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; +import org.openo.commontosca.catalog.db.entity.TemplateData; +import org.openo.commontosca.catalog.db.util.H2DbServer; +import org.openo.commontosca.catalog.db.util.HibernateSession; + +public class TemplateManagerTest { + private static TemplateManager manager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + manager = TemplateManager.getInstance(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setTemplateDao(null); + DaoManager.getInstance().setServiceTemplateDao(null); + DaoManager.getInstance().setNodeTemplateDao(null); + H2DbServer.shutDown(); + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Before + public void setUp() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + TemplateData data = new TemplateData(); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + serviceData.setCsarId("10001"); + serviceData.setServiceTemplateId("20001"); + serviceData.setRowData("EEEEEEWERWEREWRERWEREW"); + serviceData.setOperations("SDFSDFDSERWERWE"); + serviceData.setVendor("ZTE"); + serviceData.setVersion("v1.0"); + NodeTemplateData nodeData = new NodeTemplateData(); + nodeData.setName("node"); + nodeData.setNodeTemplateId("30001"); + nodeData.setServiceTemplateId("20001"); + nodelist.add(nodeData); + data.setServiceTemplate(serviceData); + data.setNodeTemplates(nodelist); + try { + manager.addServiceTemplate(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @After + public void tearDown() { + try { + manager.deleteServiceTemplateById("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testAddServiceTemplateRepeat() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + TemplateData data = new TemplateData(); + data.setServiceTemplate(serviceData); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + serviceData.setCsarId("10001"); + serviceData.setServiceTemplateId("20001"); + serviceData.setVendor("ZTE"); + serviceData.setVersion("v1.0"); + NodeTemplateData nodeData = new NodeTemplateData(); + nodeData.setName("node"); + nodeData.setServiceTemplateId("20001"); + nodelist.add(nodeData); + data.setNodeTemplates(nodelist); + try { + manager.addServiceTemplate(data); + Assert.fail("no exception"); + } catch (CatalogResourceException e) { + Assert.assertTrue(true); + } + } + + @Test + public void testQueryServiceTemplateById() { + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = manager.queryServiceTemplateById("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryServiceTemplate() { + + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = manager.queryServiceTemplate(null, "v1.0", "ZTE"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + + } + + @Test + public void testQueryNodeTemplateBySeriviceTemplateId() { + ArrayList<NodeTemplateData> list = new ArrayList<NodeTemplateData>(); + try { + list = manager.queryNodeTemplateBySeriviceTemplateId("20001"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryNodeTemplateById() { + ArrayList<NodeTemplateData> list = new ArrayList<NodeTemplateData>(); + try { + list = manager.queryNodeTemplateById("20001", null); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateMappingManagerTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateMappingManagerTest.java new file mode 100644 index 00000000..4f952e47 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/TemplateMappingManagerTest.java @@ -0,0 +1,157 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.resource; + +import java.util.ArrayList; + +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.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.dao.DaoManager; +import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData; +import org.openo.commontosca.catalog.db.util.H2DbServer; +import org.openo.commontosca.catalog.db.util.HibernateSession; + +public class TemplateMappingManagerTest { + private static TemplateManager manager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + manager = TemplateManager.getInstance(); + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setTemplateDao(null); + H2DbServer.shutDown(); + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Before + public void setUp() { + ServiceTemplateMappingData serviceMappingData = new ServiceTemplateMappingData(); + serviceMappingData.setCapabilities("wsectdSDFSDFDSXCVFertregdDFGDFG"); + serviceMappingData.setRequirements("REWREWRWE#$#"); + serviceMappingData.setNodeType("NS"); + serviceMappingData.setServiceTemplateId("10020"); + serviceMappingData.setMappingId("10000"); + try { + manager.addServiceTemplateMapping(serviceMappingData); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @After + public void tearDown() { + try { + manager.deleteServiceTemplateMappingById("10000"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testAddServiceTemplateRepeat() { + ServiceTemplateMappingData serviceMappingData = new ServiceTemplateMappingData(); + serviceMappingData.setCapabilities("wsectdSDFSDFDSXCVFertregdDFGDFG"); + serviceMappingData.setRequirements("REWREWRWE#$#"); + serviceMappingData.setNodeType("NS"); + serviceMappingData.setServiceTemplateId("10020"); + serviceMappingData.setMappingId("10000"); + try { + manager.addServiceTemplateMapping(serviceMappingData); + Assert.fail("no exception"); + } catch (CatalogResourceException e) { + Assert.assertTrue(true); + } + } + + @Test + public void testServiceTemplateMappingById() { + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMappingById("10000"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryServiceTemplateMapping() { + + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + try { + list = manager.queryServiceTemplateMapping("NS", ""); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + try { + list = manager.queryServiceTemplateMapping("", "10020"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testDeleteServiceTemplateMapping() { + + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + manager.deleteServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + try { + list = manager.queryServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() == 0); + } + + @Test + public void testQueryAllServiceTemplateMapping() { + + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMapping("", ""); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/dao/PackageDaoTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/dao/PackageDaoTest.java new file mode 100644 index 00000000..b61fde9e --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/resource/dao/PackageDaoTest.java @@ -0,0 +1,136 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.resource.dao; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +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.openo.commontosca.catalog.db.common.Parameters; +import org.openo.commontosca.catalog.db.dao.PackageDao; +import org.openo.commontosca.catalog.db.exception.CatalogResourceException; +import org.openo.commontosca.catalog.db.util.HqlFactory; +import org.openo.commontosca.catalog.db.entity.PackageData; +import org.openo.commontosca.catalog.db.util.H2DbServer; +import org.openo.commontosca.catalog.db.util.HibernateSession; + +public class PackageDaoTest { + + private static PackageDao packageDao; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + packageDao = new PackageDao(HibernateSession.init()); + + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Before + public void setUp() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + data.setName("AG"); + try { + packageDao.create(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @After + public void tearDown() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + try { + packageDao.delete(data); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + } + + @Test + public void testQueryPackageById() { + Map<String, String> queryParam = new HashMap<String, String>(); + queryParam.put(Parameters.csarId.name(), "10001"); + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = (ArrayList<PackageData>) packageDao.query(queryParam); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testUpdatePackage() { + PackageData data = new PackageData(); + data.setSize("20M"); + try { + packageDao.update(data, HqlFactory.getOidFilter(Parameters.csarId.name(), "10001")); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + Map<String, String> queryParam = new HashMap<String, String>(); + queryParam.put(Parameters.csarId.name(), "10001"); + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = (ArrayList<PackageData>) packageDao.query(queryParam); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + assertTrue(list.size() > 0 && list.get(0).getSize().equals("20M")); + } + + @Test + public void testDeleteByOid() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + try { + packageDao.delete(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + Map<String, String> queryParam = new HashMap<String, String>(); + queryParam.put(Parameters.csarId.name(), "10001"); + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = (ArrayList<PackageData>) packageDao.query(queryParam); + } catch (CatalogResourceException e) { + Assert.fail("Exception" + e.getMessage()); + } + assertEquals(list.size(), 0); + } + +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/CatalogDbUtilTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/CatalogDbUtilTest.java new file mode 100644 index 00000000..cd923160 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/CatalogDbUtilTest.java @@ -0,0 +1,58 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.util; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CatalogDbUtilTest { + + @Test + public void when_generate_id_is_not_null() { + String actual_uuid = CatalogDbUtil.generateId(); + assertNotNull(actual_uuid); + } + + @Test + public void when_input_empty_string_output_false() { + boolean expect = false; + boolean actual = CatalogDbUtil.isNotEmpty(""); + assertEquals(expect, actual); + } + + @Test + public void when_input_blan_string_output_true() { + boolean expect = true; + boolean actual = CatalogDbUtil.isNotEmpty(" "); + assertEquals(expect, actual); + } + + @Test + public void when_input_null_string_output_false() { + boolean expect = false; + boolean actual = CatalogDbUtil.isNotEmpty(null); + assertEquals(expect, actual); + } + + @Test + public void when_input_str_string_output_true() { + boolean expect = true; + boolean actual = CatalogDbUtil.isNotEmpty("str"); + assertEquals(expect, actual); + } + +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServer.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServer.java new file mode 100644 index 00000000..ceb3c7c0 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServer.java @@ -0,0 +1,51 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.util; + +import java.sql.SQLException; + +import org.h2.tools.Server; + +public class H2DbServer { + + private static Server h2DbWebServer; + private static Server h2DbTcpServer; + + public static void startUp() { + try { + h2DbWebServer = + Server.createWebServer(new String[] {"-web", "-webAllowOthers", "-webPort", + "8206"}); + h2DbWebServer.start(); + + h2DbTcpServer = + Server.createTcpServer(new String[] {"-tcp", "-tcpAllowOthers", "-tcpPort", + "8205"}); + h2DbTcpServer.start(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static void shutDown() { + if (h2DbWebServer.isRunning(true)) { + h2DbWebServer.shutdown(); + } + if (h2DbTcpServer.isRunning(true)) { + h2DbTcpServer.shutdown(); + } + } +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServerUtil.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServerUtil.java new file mode 100644 index 00000000..033e49f2 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/H2DbServerUtil.java @@ -0,0 +1,58 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.util; + +import java.io.File; +import java.net.URISyntaxException; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.SQLExec; +import org.apache.tools.ant.types.EnumeratedAttribute; + +public class H2DbServerUtil { + private static String resourcePath; + + public static void initTable() { + init(); + SQLExec sqlExec = new SQLExec(); + // set db connetc parameter + sqlExec.setDriver("org.h2.Driver"); + sqlExec.setUrl("jdbc:h2:tcp://localhost:8205/" + resourcePath + "db/catalog"); + sqlExec.setUserid("catalog"); + sqlExec.setPassword("catalog"); + // execute sql + sqlExec.setSrc(new File(resourcePath + "sql/catalog-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 e) { + e.printStackTrace(); + } + } + + public static void main(String args[]) { + H2DbServer.startUp(); + H2DbServerUtil.initTable(); + H2DbServer.shutDown(); + } +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HibernateSession.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HibernateSession.java new file mode 100644 index 00000000..0b031a7a --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HibernateSession.java @@ -0,0 +1,79 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.util; + +import java.io.File; +import java.net.URISyntaxException; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; + +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:8205/" + + resourcePath + "db/catalog"); + 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 e) { + e.printStackTrace(); + } + final String filename = "Hibernate.cfg.xml"; + cfgfile = new File(resourcePath + filename); + } + + /** + * Destory a hibernate sessionFactory. + */ + public static void destory() { + sessionFactory.close(); + } + + /* Maybe you don't need it. */ + private static void removeCfgFile() { + if (cfgfile.exists()) { + cfgfile.deleteOnExit(); + } + } + + public static void main(String[] args) { + // createCfgFile(); + // removeCfgFile(); + + + } +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HqlFactoryTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HqlFactoryTest.java new file mode 100644 index 00000000..d1070180 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/db/util/HqlFactoryTest.java @@ -0,0 +1,114 @@ +/** + * Copyright 2016 [ZTE] and others. + * + * 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.openo.commontosca.catalog.db.util; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.commontosca.catalog.db.entity.PackageData; +import org.openo.commontosca.catalog.db.entity.ServiceTemplateData; + +public class HqlFactoryTest { + + @Test + public void when_input_entity_output_udatehql() { + PackageData data = new PackageData(); + String filter = "csarId='xd03dsfsdfsfsdfsd'"; + data.setName("csarName"); + data.setType("NS"); + String expect = + "update PackageData set name='csarName',type='NS' where csarId='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() { + PackageData data = new PackageData(); + String filter = "csarId"; + data.setName("csarName"); + data.setType("NS"); + String expect = + "select q.csarId from PackageData as q where q.name='csarName' and q.type='NS'"; + String actual = HqlFactory.getQueryHql(data, filter); + assertEquals(expect, actual); + } + + @Test + public void when_input_entity_output_getQueryHqlByFilter() { + PackageData data = new PackageData(); + String filter = "csarId"; + data.setName("csarName"); + data.setType("NS"); + String expect = + " from ServiceTemplateData as a where a.csarId in(select q.csarId from PackageData as q where q.name='csarName' and q.type='NS')"; + String actual = HqlFactory.getQueryHqlByFilter(ServiceTemplateData.class, data, filter); + assertEquals(expect, actual); + } + + @Test + public void when_input_entity_output_getDeleteHqlByFilter() { + PackageData data = new PackageData(); + String filter = "csarId"; + data.setName("csarName"); + data.setType("NS"); + String expect = + "delete from ServiceTemplateData as b where b.csarId in(select q.csarId from PackageData as q where q.name='csarName' and q.type='NS')"; + String actual = HqlFactory.getDeleteHqlByFilter(ServiceTemplateData.class, data, filter); + assertEquals(expect, actual); + } +} diff --git a/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java new file mode 100644 index 00000000..066710c4 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/java/org/openo/commontosca/catalog/wrapper/PackageWrapperTest.java @@ -0,0 +1,318 @@ +/**
+ * Copyright 2016 [ZTE] and others.
+ *
+ * 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.openo.commontosca.catalog.wrapper;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+
+import javax.ws.rs.core.Response;
+
+import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.openo.commontosca.catalog.CatalogAppConfiguration;
+import org.openo.commontosca.catalog.common.Config;
+import org.openo.commontosca.catalog.common.MsbAddrConfig;
+import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
+import org.openo.commontosca.catalog.db.resource.PackageManager;
+import org.openo.commontosca.catalog.filemanage.entity.FileLink;
+import org.openo.commontosca.catalog.common.HttpServerAddrConfig;
+import org.openo.commontosca.catalog.common.HttpServerPathConfig;
+import org.openo.commontosca.catalog.db.dao.DaoManager;
+import org.openo.commontosca.catalog.db.entity.PackageData;
+import org.openo.commontosca.catalog.db.util.H2DbServer;
+import org.openo.commontosca.catalog.db.util.HibernateSession;
+import org.openo.commontosca.catalog.entity.EnumOperationalState;
+import org.openo.commontosca.catalog.entity.EnumProcessState;
+import org.openo.commontosca.catalog.entity.EnumUsageState;
+import org.openo.commontosca.catalog.entity.response.CsarFileUriResponse;
+import org.openo.commontosca.catalog.entity.response.PackageMeta;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author 00164331
+ *
+ */
+public class PackageWrapperTest {
+ private static String resourcePath;
+
+ static {
+ MsbAddrConfig.setMsbAddress("http://127.0.0.1:80");
+ }
+ static {
+ HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
+ }
+ static {
+ HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
+ }
+
+ // @Mock
+ private static PackageManager manager;
+
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws CatalogResourceException {
+ CatalogAppConfiguration configuration = new CatalogAppConfiguration();
+ H2DbServer.startUp();
+ DaoManager.getInstance().setSessionFactory(HibernateSession.init());
+ manager = PackageManager.getInstance();
+ Config.setConfigration(configuration);
+ System.out.println("Set up before class");
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ ArrayList<PackageData> packageList = manager.queryPackage(null, null, null, null, null);
+ if (packageList != null && packageList.size() > 0) {
+ for (int i = 0; i < packageList.size(); i++) {
+ String package_oid = packageList.get(i).getCsarId();
+ manager.deletePackage(package_oid);
+ }
+ }
+
+ // PowerMockito.mockStatic(PackageManager.class);
+ // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData);
+ // PowerMock.replayAll();
+ PackageData packageData = new PackageData();
+ packageData = getPackageData();
+ manager.addPackage(packageData);
+ }
+
+ // @Ignore
+ @Test
+ public void testUploadPackage() throws Exception {
+ InputStream ins = null;
+ Response result = null;
+ Response result1 = null;
+ Response result2 = null;
+ // PackageData packageData = new PackageData();
+ // packageData = getPackageData();
+
+ FormDataContentDisposition fileDetail =
+ FormDataContentDisposition.name("fileName").fileName("NanocellGW.csar").build();
+
+ try {
+ resourcePath = HibernateSession.class.getResource("/").toURI().getPath();
+ } catch (URISyntaxException e) {
+ e.printStackTrace();
+ }
+ final String filename = "NanocellGW.csar";
+ File packageFile = new File(resourcePath + filename);
+ try {
+ ins = new FileInputStream(packageFile);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ if (ins != null) {
+ try {
+ result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ assertEquals(200, result.getStatus());
+ assertNotNull(result.getEntity());
+
+ try {
+ result1 = PackageWrapper.getInstance().uploadPackage(null, fileDetail, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertEquals(500, result1.getStatus());
+
+ try {
+ result2 = PackageWrapper.getInstance().uploadPackage(ins, null, null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ assertEquals(500, result2.getStatus());
+ }
+
+ @Test
+ public void testQueryPackageById() throws Exception {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas = getPackageMetaList();
+ // PackageManager packageManager = mock(PackageManager.class);
+ // when(packageManager.queryPackageByCsarId(anyString())).thenThrow(new Exception());
+ // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(packageManager);
+ // PowerMockito.mockStatic(PackageManager.class);
+ // PowerMockito.when(PackageManager.getInstance()).thenReturn(manager);
+ // PowerMock.replayAll();
+ // when(manager.queryPackageByCsarId(anyString())).thenThrow(new Exception());
+ // PowerMockito.whenNew(PackageManager.class).withNoArguments().thenReturn(manager);
+
+ Response result = PackageWrapper.getInstance().queryPackageById("1");
+ assertEquals(200, result.getStatus());
+ assertEquals(metas, result.getEntity());
+
+ }
+
+ @Test
+ public void testQueryPackageByCond() {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas = getPackageMetaList();
+ System.out.println("Test query package by Id");
+ Response result =
+ PackageWrapper.getInstance().queryPackageListByCond("NanocellGW", "ZTE", "V1.0",
+ "false", "NSAR");
+ assertEquals(200, result.getStatus());
+ assertEquals(metas, result.getEntity());
+ }
+
+ @Test
+ public void testUpdatePackageStatus() {
+ System.out.println("Test update package status");
+ Response result =
+ PackageWrapper.getInstance().updatePackageStatus("1", "Enabled", "NotInUse",
+ "true", "onBoarding", "true");
+ assertEquals(200, result.getStatus());
+ }
+
+ @Test
+ public void testGetCsarFileUri() {
+ System.out.println("Test get csar file uri ");
+ CsarFileUriResponse expectResult = new CsarFileUriResponse();
+ String csarFileUri =
+ MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ String localUri =
+ HttpServerPathConfig.getHttpServerPath()
+ + "NSAR/ZTE/NanocellGW/v1.0/NanocellGW/images/segw.img";
+ File srcDir = new File(localUri);
+ String localPath = srcDir.getAbsolutePath().replace("\\", "/");
+
+ expectResult.setDownloadUri(csarFileUri);
+ expectResult.setLocalPath(localPath);
+ Response result = PackageWrapper.getInstance().getCsarFileUri("1", "/images/segw.img");
+ assertEquals(200, result.getStatus());
+ assertEquals(expectResult, result.getEntity());
+ }
+
+ @Ignore
+ @Test
+ public void testGetPlansUri() {
+ System.out.println("Test get csar plans uri ");
+ ArrayList<FileLink> expectResult = new ArrayList<FileLink>();
+ FileLink fileLink1 = new FileLink();
+ FileLink fileLink2 = new FileLink();
+ fileLink1.setFileName("init.zip");
+ fileLink1.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/Plans/init.zip");
+ expectResult.add(fileLink1);
+ fileLink2.setFileName("delete.zip");
+ fileLink2.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/Plans/delete.zip");
+ expectResult.add(fileLink2);
+ Response result = PackageWrapper.getInstance().getCsarPlansUri("1");
+ assertEquals(200, result.getStatus());
+ assertEquals(expectResult, result.getEntity());
+ }
+
+ @Test
+ public void testDelPackage() {
+ System.out.println("Test delete package ");
+ Response result = PackageWrapper.getInstance().delPackage("1");
+ assertEquals(204, result.getStatus());
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ ArrayList<PackageData> packageList = manager.queryPackageByCsarId("1");
+ if (packageList != null && packageList.size() != 0) {
+ manager.deletePackage("1");
+ } else {
+ return;
+ }
+ System.out.println("Tear down");
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ try {
+ HibernateSession.destory();
+ DaoManager.getInstance().setDaoNull();
+ H2DbServer.shutDown();
+ } catch (Exception e) {
+ Assert.fail("Exception" + e.getMessage());
+ }
+ }
+
+ private PackageData getPackageData() {
+ PackageData packageData = new PackageData();
+ packageData.setCsarId("1");
+ packageData.setCreateTime("2016-06-29 03:33:15");
+ packageData.setDeletionPending("false");
+ packageData.setDownloadUri("/NSAR/ZTE/NanocellGW/v1.0/");
+ packageData.setFormat("yml");
+ packageData.setModifyTime("2016-06-29 03:33:15");
+ packageData.setName("NanocellGW");
+ packageData.setOnBoardState("false");
+ packageData.setOperationalState("Disabled");
+ packageData.setProvider("ZTE");
+ packageData.setSize("0.93M");
+ packageData.setType("NSAR");
+ packageData.setUsageState("InUse");
+ packageData.setVersion("V1.0");
+ packageData.setProcessState("normal");
+ return packageData;
+ }
+
+ private ArrayList<PackageData> getPackageDataList() {
+ ArrayList<PackageData> packageDataList = new ArrayList<PackageData>();
+ PackageData packageData = new PackageData();
+ packageData = getPackageData();
+ packageDataList.add(packageData);
+ return packageDataList;
+ }
+
+ private ArrayList<PackageMeta> getPackageMetaList() {
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ PackageMeta meta = new PackageMeta();
+ meta.setCreateTime("2016-06-29 03:33:15");
+ meta.setCsarId("1");
+ meta.setDeletionPending(false);
+ meta.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/NanocellGW.csar");
+ meta.setFormat("yml");
+ meta.setModifyTime("2016-06-29 03:33:15");
+ meta.setName("NanocellGW");
+ meta.setOperationalState(EnumOperationalState.valueOf("Disabled"));
+ meta.setProvider("ZTE");
+ meta.setSize("0.93M");
+ meta.setType("NSAR");
+ meta.setUsageState(EnumUsageState.valueOf("InUse"));
+ meta.setVersion("V1.0");
+ meta.setOnBoardState("false");
+ meta.setProcessState(EnumProcessState.valueOf("normal"));
+ metas.add(meta);
+ return metas;
+ }
+}
diff --git a/catalog-core/catalog-mgr/src/test/resources/Hibernate.cfg.xml b/catalog-core/catalog-mgr/src/test/resources/Hibernate.cfg.xml new file mode 100644 index 00000000..e0b13c51 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/resources/Hibernate.cfg.xml @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2016 [ZTE] and others. + + 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:8205/./db/catalog</property> + <property name="hibernate.connection.username">catalog</property> + <property name="hibernate.connection.password">catalog</property> + <property name="hbm2ddl">update</property> + <property name="current_session_context_class">thread</property> + <mapping class="org.openo.commontosca.catalog.db.entity.NodeTemplateData"/> + <mapping class="org.openo.commontosca.catalog.db.entity.PackageData"/> + <mapping class="org.openo.commontosca.catalog.db.entity.ServiceTemplateData"/> + <mapping class="org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData"/> +</session-factory> +</hibernate-configuration>
\ No newline at end of file diff --git a/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar b/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar Binary files differnew file mode 100644 index 00000000..d9efb502 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/resources/NanocellGW.csar diff --git a/catalog-core/catalog-mgr/src/test/resources/db/catalog.mv.db b/catalog-core/catalog-mgr/src/test/resources/db/catalog.mv.db Binary files differnew file mode 100644 index 00000000..b1d596f4 --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/resources/db/catalog.mv.db diff --git a/catalog-core/catalog-mgr/src/test/resources/sql/catalog-resource-createObj-mysql.sql b/catalog-core/catalog-mgr/src/test/resources/sql/catalog-resource-createObj-mysql.sql new file mode 100644 index 00000000..3966c7dc --- /dev/null +++ b/catalog-core/catalog-mgr/src/test/resources/sql/catalog-resource-createObj-mysql.sql @@ -0,0 +1,74 @@ +-- +-- Copyright 2016 [ZTE] and others. +-- +-- 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 catalog_package_table; + +CREATE TABLE catalog_package_table ( + CSARID VARCHAR(200) NOT NULL, + DOWNLOADURI VARCHAR(200) NULL, + SIZE VARCHAR(100) NULL, + FORMAT VARCHAR(100) NULL, + CREATETIME VARCHAR(100) NULL, + DELETIONPENDING VARCHAR(100) NULL, + MODIFYTIME VARCHAR(100) NULL, + OPERATIONALSTATE VARCHAR(100) NULL, + USAGESTATE VARCHAR(100) NULL, + ONBOARDSTATE VARCHAR(100) NULL, + NAME VARCHAR(100) NULL, + VERSION VARCHAR(20) NULL, + PROVIDER VARCHAR(300) NULL, + TYPE VARCHAR(300) NULL, + PROCESSSTATE VARCHAR(100) NULL, + CONSTRAINT CATALOG_PACKAGE_TABLE_OID PRIMARY KEY(CSARID) +); + +DROP TABLE IF EXISTS catalog_service_template_table; +CREATE TABLE catalog_service_template_table ( + SERVICETEMPLATEID VARCHAR(200) NOT NULL, + TEMPLATENAME VARCHAR(100) NULL, + TYPE VARCHAR(50) NULL, + VENDOR VARCHAR(100) NULL, + VERSION VARCHAR(20) NULL, + CSARID VARCHAR(100) NULL, + INPUTS LONGTEXT NULL, + ROWDATA LONGTEXT NULL, + OPERATIONS LONGTEXT NULL, + DOWNLOADURI VARCHAR(200) NULL, + + CONSTRAINT CATALOG_SERVICE_TEMPLATE_TABLE_OID PRIMARY KEY(SERVICETEMPLATEID) +); + +DROP TABLE IF EXISTS catalog_node_template_table; +CREATE TABLE catalog_node_template_table ( + NODETEMPLATEID VARCHAR(200) NOT NULL, + NAME VARCHAR(100) NULL, + SERVICETEMPLATEID VARCHAR(200) NULL, + TYPE VARCHAR(50) NULL, + PROPERTIES LONGTEXT NULL, + RELATIONSHIPS LONGTEXT NULL, + + CONSTRAINT catalog_node_template_table PRIMARY KEY(NODETEMPLATEID) +); +DROP TABLE IF EXISTS catalog_model_substitution_mapping_table; +CREATE TABLE catalog_model_substitution_mapping_table ( + MAPPINGID VARCHAR(200) NOT NULL, + NODETYPE VARCHAR(100) NULL, + SERVICETEMPLATEID VARCHAR(200) NULL, + REQUIREMENTS LONGTEXT NULL, + CAPABILITIES LONGTEXT NULL, + + CONSTRAINT catalog_model_substitution_mapping_table PRIMARY KEY(MAPPINGID) +); |