diff options
author | 2016-08-31 14:22:36 +0800 | |
---|---|---|
committer | 2016-08-31 14:22:36 +0800 | |
commit | 2f74a6be8973eab31b8d097117d2d1d12366a0d9 (patch) | |
tree | dc85eccc822b822d403872735db3acceba7edc6a /catalog-core/catalog-mgr/src/test | |
parent | e2ce3e29258bdd8894b2a42fc88a3546d640a82e (diff) |
modify catalog code fit for check style
Change-Id: I782b72fc1a4af37f20116fde624a4826d4154546
Signed-off-by: nancylizi <li.zi30@zte.com.cn>
Diffstat (limited to 'catalog-core/catalog-mgr/src/test')
11 files changed, 1133 insertions, 1007 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 index 8e212103..f0b27bf6 100644 --- 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 @@ -13,9 +13,9 @@ * 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; @@ -23,156 +23,178 @@ 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.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.util.H2DbServer; import org.openo.commontosca.catalog.db.util.HibernateSession; +import java.util.ArrayList; + 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(); - } + private static PackageManager packageManager; + private static TemplateManager templateManager; - @AfterClass - public static void tearDownAfterClass() throws Exception { - try { - HibernateSession.destory(); - DaoManager.getInstance().setDaoNull(); - H2DbServer.shutDown(); - } catch (Exception e) { - Assert.fail("Exception" + e.getMessage()); - } - } + /** + * startup H2DB session before class. + * @throws Exception e + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + packageManager = PackageManager.getInstance(); + templateManager = TemplateManager.getInstance(); + } - @Before - public void setUp() { - initPackageInfo(); - initTemplateInfo(); + /** + * destory H2DB session after class. + * @throws Exception e + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setDaoNull(); + H2DbServer.shutDown(); + } catch (Exception e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - 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()); - } - } + @Before + public void setUp() { + initPackageInfo(); + initTemplateInfo(); + } - public void deletePackageInfo() { - try { - packageManager.deletePackage("10001"); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + /** + * init package information. + */ + 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 e1) { + Assert.fail("Exception" + e1.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()); - } + /** + * delete package information. + */ + public void deletePackageInfo() { + try { + packageManager.deletePackage("10001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - public void deleteTemplate() { - try { - templateManager.deleteServiceTemplateById("20001"); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + /** + * init template information. + */ + public void initTemplateInfo() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + 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"); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + nodelist.add(nodeData); + TemplateData data = new TemplateData(); + data.setServiceTemplate(serviceData); + data.setNodeTemplates(nodelist); + try { + templateManager.addServiceTemplate(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - @After - public void tearDown() { - deleteTemplate(); - deletePackageInfo(); + /** + * delete template. + */ + public void deleteTemplate() { + try { + templateManager.deleteServiceTemplateById("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - @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); + @After + public void tearDown() { + deleteTemplate(); + deletePackageInfo(); + } + + @Test + public void testDeletePackageByServiceTemplateId() { + try { + packageManager.deletePackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = packageManager.queryPackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e2) { + Assert.fail("Exception" + e2.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 testQueryPackageByServiceTemplateId() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = packageManager.queryPackageByServiceTemplateId("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 testDeleteServiceTemplateByCsarPackageInfo() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + templateManager.deleteServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + try { + list = templateManager.queryServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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); + @Test + public void testQueryServiceTemplateByCsarPackageInfo() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = templateManager.queryServiceTemplateByCsarPackageInfo(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 index 52ec701f..fc847a60 100644 --- 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 @@ -13,13 +13,11 @@ * 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; @@ -28,138 +26,157 @@ 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.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.util.H2DbServer; import org.openo.commontosca.catalog.db.util.HibernateSession; -public class PackageManagerTest { - private static PackageManager manager; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; - @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()); - } +public class PackageManagerTest { + private static PackageManager manager; + + /** + * startup db session before class. + * @throws Exception e + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + manager = PackageManager.getInstance(); + } + + /** + * destory db session after class. + * @throws Exception e + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setPackageDao(null); + H2DbServer.shutDown(); + } catch (Exception e1) { + Assert.fail("Exception" + e1.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()); - } + } + + /** + * create data before test. + */ + @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 e1) { + Assert.fail("Exception" + e1.getMessage()); } - - @After - public void tearDown() { - try { - manager.deletePackage("10001"); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + } + + /** + * delete data after test. + */ + @After + public void tearDown() { + try { + manager.deletePackage("10001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 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 e1) { + 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 testQueryPackageByCsarId_exist() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackageByCsarId("10001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 e1) { + Assert.fail("Exception" + e1.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_exist() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackage("AG", "ZTE", "v1.0", null, null); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 testQueryPackage_not_exist() { + ArrayList<PackageData> list = new ArrayList<PackageData>(); + try { + list = manager.queryPackage("AG", "ZTE", "v2.0", null, null); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } - - @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")); + 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 e1) { + Assert.fail("Exception" + e1.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 index 66b25048..41dcfab1 100644 --- 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 @@ -13,9 +13,9 @@ * 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; @@ -23,138 +23,154 @@ 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.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.util.H2DbServer; import org.openo.commontosca.catalog.db.util.HibernateSession; +import java.util.ArrayList; + public class TemplateManagerTest { - private static TemplateManager manager; + private static TemplateManager manager; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - H2DbServer.startUp(); - DaoManager.getInstance().setSessionFactory(HibernateSession.init()); - manager = TemplateManager.getInstance(); - } + /** + * startup db session before class. + * @throws Exception e + */ + @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()); - } + /** + * destory db session after class. + * @throws Exception e + */ + @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 e1) { + Assert.fail("Exception" + e1.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()); - } + /** + * create data before test. + */ + @Before + public void setUp() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + 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"); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + nodelist.add(nodeData); + TemplateData data = new TemplateData(); + data.setServiceTemplate(serviceData); + data.setNodeTemplates(nodelist); + try { + manager.addServiceTemplate(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - @After - public void tearDown() { - try { - manager.deleteServiceTemplateById("20001"); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + /** + * delete data after test. + */ + @After + public void tearDown() { + try { + manager.deleteServiceTemplateById("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 testAddServiceTemplateRepeat() { + ServiceTemplateData serviceData = new ServiceTemplateData(); + TemplateData data = new TemplateData(); + data.setServiceTemplate(serviceData); + serviceData.setCsarId("10001"); + serviceData.setServiceTemplateId("20001"); + serviceData.setVendor("ZTE"); + serviceData.setVersion("v1.0"); + NodeTemplateData nodeData = new NodeTemplateData(); + nodeData.setName("node"); + nodeData.setServiceTemplateId("20001"); + ArrayList<NodeTemplateData> nodelist = new ArrayList<NodeTemplateData>(); + nodelist.add(nodeData); + data.setNodeTemplates(nodelist); + try { + manager.addServiceTemplate(data); + Assert.fail("no exception"); + } catch (CatalogResourceException e1) { + 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 testQueryServiceTemplateById() { + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = manager.queryServiceTemplateById("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 testQueryServiceTemplate() { + ArrayList<ServiceTemplateData> list = new ArrayList<ServiceTemplateData>(); + try { + list = manager.queryServiceTemplate(null, "v1.0", "ZTE"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 testQueryNodeTemplateBySeriviceTemplateId() { + ArrayList<NodeTemplateData> list = new ArrayList<NodeTemplateData>(); + try { + list = manager.queryNodeTemplateBySeriviceTemplateId("20001"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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); + @Test + public void testQueryNodeTemplateById() { + ArrayList<NodeTemplateData> list = new ArrayList<NodeTemplateData>(); + try { + list = manager.queryNodeTemplateById("20001", null); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 index 4f952e47..09c6d181 100644 --- 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 @@ -13,9 +13,8 @@ * 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; +package org.openo.commontosca.catalog.db.resource; import org.junit.After; import org.junit.AfterClass; @@ -23,135 +22,152 @@ 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.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.util.H2DbServer; import org.openo.commontosca.catalog.db.util.HibernateSession; -public class TemplateMappingManagerTest { - private static TemplateManager manager; +import java.util.ArrayList; - @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()); - } +public class TemplateMappingManagerTest { + private static TemplateManager manager; + + /** + * startup db session before class. + * @throws Exception e + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + H2DbServer.startUp(); + DaoManager.getInstance().setSessionFactory(HibernateSession.init()); + manager = TemplateManager.getInstance(); + } + + /** + * destory db session after class. + * @throws Exception e + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + DaoManager.getInstance().setTemplateDao(null); + H2DbServer.shutDown(); + } catch (Exception e1) { + Assert.fail("Exception" + e1.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()); - } + } + + /** + * create data before test. + */ + @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 e1) { + Assert.fail("Exception" + e1.getMessage()); } - - @After - public void tearDown() { - try { - manager.deleteServiceTemplateMappingById("10000"); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + } + + /** + * delete data after test. + */ + @After + public void tearDown() { + try { + manager.deleteServiceTemplateMappingById("10000"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 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 e1) { + 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 testServiceTemplateMappingById() { + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMappingById("10000"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + Assert.assertTrue(list.size() > 0); + } + + @Test + public void testQueryServiceTemplateMapping() { - @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); + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + Assert.assertTrue(list.size() > 0); + try { + list = manager.queryServiceTemplateMapping("NS", ""); + } catch (CatalogResourceException e2) { + Assert.fail("Exception" + e2.getMessage()); + } + Assert.assertTrue(list.size() > 0); + try { + list = manager.queryServiceTemplateMapping("", "10020"); + } catch (CatalogResourceException e3) { + Assert.fail("Exception" + e3.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 testDeleteServiceTemplateMapping() { + + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + manager.deleteServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); + } + try { + list = manager.queryServiceTemplateMapping("NS", "10020"); + } catch (CatalogResourceException e2) { + Assert.fail("Exception" + e2.getMessage()); } + Assert.assertTrue(list.size() == 0); + } - @Test - public void testQueryAllServiceTemplateMapping() { + @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); + ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>(); + try { + list = manager.queryServiceTemplateMapping("", ""); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 index b61fde9e..4a552f1d 100644 --- 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 @@ -13,14 +13,12 @@ * 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; @@ -30,107 +28,127 @@ 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.exception.CatalogResourceException; import org.openo.commontosca.catalog.db.util.H2DbServer; import org.openo.commontosca.catalog.db.util.HibernateSession; +import org.openo.commontosca.catalog.db.util.HqlFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; public class PackageDaoTest { - private static PackageDao packageDao; + private static PackageDao packageDao; - @BeforeClass - public static void setUpBeforeClass() throws Exception { - H2DbServer.startUp(); - packageDao = new PackageDao(HibernateSession.init()); + /** + * setup db session before class. + * @throws Exception e + */ + @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()); - } + /** + * shutdown db session before class. + * @throws Exception e + */ + @AfterClass + public static void tearDownAfterClass() throws Exception { + try { + HibernateSession.destory(); + H2DbServer.shutDown(); + } catch (Exception e1) { + Assert.fail("Exception" + e1.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()); - } + /** + * create data before test. + * @throws Exception e + */ + @Before + public void setUp() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + data.setName("AG"); + try { + packageDao.create(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.getMessage()); } + } - @After - public void tearDown() { - PackageData data = new PackageData(); - data.setCsarId("10001"); - try { - packageDao.delete(data); - } catch (CatalogResourceException e) { - Assert.fail("Exception" + e.getMessage()); - } + /** + * delete data after test. + * @throws Exception e + */ + @After + public void tearDown() { + PackageData data = new PackageData(); + data.setCsarId("10001"); + try { + packageDao.delete(data); + } catch (CatalogResourceException e1) { + Assert.fail("Exception" + e1.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 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 e1) { + Assert.fail("Exception" + e1.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 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 e1) { + Assert.fail("Exception" + e1.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); + @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 e1) { + Assert.fail("Exception" + e1.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 index cd923160..8172d26c 100644 --- 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 @@ -13,46 +13,50 @@ * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +//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); - } + @Test + public void when_generate_id_is_not_null() { + String actualUuid = CatalogDbUtil.generateId(); + assertNotNull(actualUuid); + } + + @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 index ceb3c7c0..ee62a306 100644 --- 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 @@ -13,39 +13,45 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.openo.commontosca.catalog.db.util; +import org.h2.tools.Server; + 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(); - } + private static Server h2DbWebServer; + private static Server h2DbTcpServer; + + /** + * start up db service. + */ + 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 e1) { + e1.printStackTrace(); } + } - public static void shutDown() { - if (h2DbWebServer.isRunning(true)) { - h2DbWebServer.shutdown(); - } - if (h2DbTcpServer.isRunning(true)) { - h2DbTcpServer.shutdown(); - } + /** + * shut down db service. + */ + 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 index 033e49f2..b10c377f 100644 --- 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 @@ -13,46 +13,53 @@ * 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; +package org.openo.commontosca.catalog.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; + 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(); - } + /** + * init data 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: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(); - } + private static void init() { + try { + resourcePath = HibernateSession.class.getResource("/").toURI().getPath(); + } catch (URISyntaxException e1) { + e1.printStackTrace(); } + } - public static void main(String args[]) { - H2DbServer.startUp(); - H2DbServerUtil.initTable(); - H2DbServer.shutDown(); - } + /** + * test. + */ + public static void main() { + 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 index 0b031a7a..ded139a7 100644 --- 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 @@ -13,67 +13,71 @@ * 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; +package org.openo.commontosca.catalog.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 File cfgfile = null; - private static ServiceRegistry serviceRegistry = null; - private static Configuration configuration = null; - private static SessionFactory sessionFactory = null; - private static String resourcePath; + 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; - } + /** + * 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); + private static void initConfigure() { + try { + resourcePath = HibernateSession.class.getResource("/").toURI().getPath(); + } catch (URISyntaxException e1) { + e1.printStackTrace(); } + final String filename = "Hibernate.cfg.xml"; + cfgfile = new File(resourcePath + filename); + } - /** - * Destory a hibernate sessionFactory. - */ - public static void destory() { - sessionFactory.close(); - } + /** + * 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(); - } + /* Maybe you don't need it. */ + private static void removeCfgFile() { + if (cfgfile.exists()) { + cfgfile.deleteOnExit(); } + } - public static void main(String[] args) { - // createCfgFile(); - // removeCfgFile(); + /** + * test. + * @param args param + */ + 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 index d1070180..23a5f5ea 100644 --- 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 @@ -13,9 +13,10 @@ * 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 static org.junit.Assert.assertEquals; import org.junit.Test; import org.openo.commontosca.catalog.db.entity.PackageData; @@ -23,92 +24,95 @@ 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_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_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_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 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 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_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_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); - } + @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 index f41a8cf7..20a0d355 100644 --- 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 @@ -13,16 +13,11 @@ * 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;
+package org.openo.commontosca.catalog.wrapper;
-import javax.ws.rs.core.Response;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.junit.After;
@@ -34,14 +29,13 @@ 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.common.MsbAddrConfig;
import org.openo.commontosca.catalog.db.dao.DaoManager;
import org.openo.commontosca.catalog.db.entity.PackageData;
+import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
+import org.openo.commontosca.catalog.db.resource.PackageManager;
import org.openo.commontosca.catalog.db.util.H2DbServer;
import org.openo.commontosca.catalog.db.util.HibernateSession;
import org.openo.commontosca.catalog.entity.EnumOnboardState;
@@ -50,270 +44,288 @@ 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 org.openo.commontosca.catalog.filemanage.entity.FileLink;
-import static org.junit.Assert.*;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
-/**
- * @author 00164331
- *
- */
-public class PackageWrapperTest {
- private static String resourcePath;
+import javax.ws.rs.core.Response;
- static {
- MsbAddrConfig.setMsbAddress("http://127.0.0.1:80");
- }
- static {
- HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
- }
- static {
- HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
- }
+public class PackageWrapperTest {
+ private static String resourcePath;
- // @Mock
- private static PackageManager manager;
+ static {
+ MsbAddrConfig.setMsbAddress("http://127.0.0.1:80");
+ }
+
+ static {
+ HttpServerAddrConfig.setHttpServerAddress("http://127.0.0.1:8080");
+ }
+
+ static {
+ HttpServerPathConfig.setHttpServerPath("../tomcat/webapps/ROOT/");
+ }
+ 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);
- }
- }
+ /**
+ * startup db session before class.
+ * @throws Exception e
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CatalogResourceException {
+ H2DbServer.startUp();
+ DaoManager.getInstance().setSessionFactory(HibernateSession.init());
+ manager = PackageManager.getInstance();
+ CatalogAppConfiguration configuration = new CatalogAppConfiguration();
+ Config.setConfigration(configuration);
+ System.out.println("Set up before class");
+ }
- // PowerMockito.mockStatic(PackageManager.class);
- // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData);
- // PowerMock.replayAll();
- PackageData packageData = new PackageData();
- packageData = getPackageData();
- manager.addPackage(packageData);
+ /**
+ * create data before test.
+ */
+ @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 packageOid = packageList.get(i).getCsarId();
+ manager.deletePackage(packageOid);
+ }
}
- // @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();
+ // PowerMockito.mockStatic(PackageManager.class);
+ // PowerMockito.when(manager.addPackage(packageData)).thenReturn(packageData);
+ // PowerMock.replayAll();
+ PackageData packageData = new PackageData();
+ packageData = getPackageData();
+ manager.addPackage(packageData);
+ }
- FormDataContentDisposition fileDetail =
- FormDataContentDisposition.name("fileName").fileName("NanocellGW.csar").build();
+ // @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();
- 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());
+ FormDataContentDisposition fileDetail =
+ FormDataContentDisposition.name("fileName").fileName("NanocellGW.csar").build();
+
+ try {
+ resourcePath = HibernateSession.class.getResource("/").toURI().getPath();
+ } catch (URISyntaxException e1) {
+ e1.printStackTrace();
+ }
+ final String filename = "NanocellGW.csar";
+ File packageFile = new File(resourcePath + filename);
+ try {
+ ins = new FileInputStream(packageFile);
+ } catch (FileNotFoundException e2) {
+ e2.printStackTrace();
+ }
+ if (ins != null) {
+ try {
+ result = PackageWrapper.getInstance().uploadPackage(ins, fileDetail, null);
+ } catch (Exception e3) {
+ e3.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 {
+ result1 = PackageWrapper.getInstance().uploadPackage(null, fileDetail, null);
+ } catch (Exception e4) {
+ e4.printStackTrace();
+ }
+ assertEquals(500, result1.getStatus());
- try {
- result2 = PackageWrapper.getInstance().uploadPackage(ins, null, null);
- } catch (Exception e) {
- e.printStackTrace();
- }
- assertEquals(500, result2.getStatus());
+ try {
+ result2 = PackageWrapper.getInstance().uploadPackage(ins, null, null);
+ } catch (Exception e5) {
+ e5.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);
+ @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());
+ 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 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 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("\\", "/");
+ @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());
- }
+ 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());
- }
+ @Ignore
+ @Test
+ public void testGetPlansUri() {
+ System.out.println("Test get csar plans uri ");
+ ArrayList<FileLink> expectResult = new ArrayList<FileLink>();
+ FileLink fileLink1 = new FileLink();
+ fileLink1.setFileName("init.zip");
+ fileLink1.setDownloadUri(MsbAddrConfig.getMsbAddress()
+ + "/NSAR/ZTE/NanocellGW/v1.0/Plans/init.zip");
+ expectResult.add(fileLink1);
+ FileLink fileLink2 = new FileLink();
+ 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();
- }
+ @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 e1) {
+ e1.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");
+ /**
+ * delete data after test.
+ */
+ @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());
- }
+ /**
+ * destory db session after class.
+ * @throws Exception e
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ try {
+ HibernateSession.destory();
+ DaoManager.getInstance().setDaoNull();
+ H2DbServer.shutDown();
+ } catch (Exception e1) {
+ Assert.fail("Exception" + e1.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("non-onBoarded");
- 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 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("non-onBoarded");
+ 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<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(EnumOnboardState.nonOnBoarded.getValue());
- meta.setProcessState(EnumProcessState.valueOf("normal"));
- metas.add(meta);
- return metas;
- }
+ private ArrayList<PackageMeta> getPackageMetaList() {
+ 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(EnumOnboardState.nonOnBoarded.getValue());
+ meta.setProcessState(EnumProcessState.valueOf("normal"));
+ ArrayList<PackageMeta> metas = new ArrayList<PackageMeta>();
+ metas.add(meta);
+ return metas;
+ }
}
|