2 * Copyright 2016 [ZTE] and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.commontosca.catalog.db.resource;
19 import org.junit.After;
20 import org.junit.AfterClass;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.openo.commontosca.catalog.db.dao.DaoManager;
26 import org.openo.commontosca.catalog.db.entity.ServiceTemplateMappingData;
27 import org.openo.commontosca.catalog.db.exception.CatalogResourceException;
28 import org.openo.commontosca.catalog.db.util.H2DbServer;
29 import org.openo.commontosca.catalog.db.util.HibernateSession;
31 import java.util.ArrayList;
34 public class TemplateMappingManagerTest {
35 private static TemplateManager manager;
38 * startup db session before class.
42 public static void setUpBeforeClass() throws Exception {
44 DaoManager.getInstance().setSessionFactory(HibernateSession.init());
45 manager = TemplateManager.getInstance();
49 * destory db session after class.
53 public static void tearDownAfterClass() throws Exception {
55 HibernateSession.destory();
56 DaoManager.getInstance().setTemplateDao(null);
57 H2DbServer.shutDown();
58 } catch (Exception e1) {
59 Assert.fail("Exception" + e1.getMessage());
64 * create data before test.
68 ServiceTemplateMappingData serviceMappingData = new ServiceTemplateMappingData();
69 serviceMappingData.setCapabilities("wsectdSDFSDFDSXCVFertregdDFGDFG");
70 serviceMappingData.setRequirements("REWREWRWE#$#");
71 serviceMappingData.setNodeType("NS");
72 serviceMappingData.setServiceTemplateId("10020");
73 serviceMappingData.setMappingId("10000");
75 manager.addServiceTemplateMapping(serviceMappingData);
76 } catch (CatalogResourceException e1) {
77 Assert.fail("Exception" + e1.getMessage());
82 * delete data after test.
85 public void tearDown() {
87 manager.deleteServiceTemplateMappingById("10000");
88 } catch (CatalogResourceException e1) {
89 Assert.fail("Exception" + e1.getMessage());
94 public void testAddServiceTemplateRepeat() {
95 ServiceTemplateMappingData serviceMappingData = new ServiceTemplateMappingData();
96 serviceMappingData.setCapabilities("wsectdSDFSDFDSXCVFertregdDFGDFG");
97 serviceMappingData.setRequirements("REWREWRWE#$#");
98 serviceMappingData.setNodeType("NS");
99 serviceMappingData.setServiceTemplateId("10020");
100 serviceMappingData.setMappingId("10000");
102 manager.addServiceTemplateMapping(serviceMappingData);
103 Assert.fail("no exception");
104 } catch (CatalogResourceException e1) {
105 Assert.assertTrue(true);
110 public void testServiceTemplateMappingById() {
111 ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>();
113 list = manager.queryServiceTemplateMappingById("10000");
114 } catch (CatalogResourceException e1) {
115 Assert.fail("Exception" + e1.getMessage());
117 Assert.assertTrue(list.size() > 0);
121 public void testQueryServiceTemplateMapping() {
123 ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>();
125 list = manager.queryServiceTemplateMapping("NS", "10020");
126 } catch (CatalogResourceException e1) {
127 Assert.fail("Exception" + e1.getMessage());
129 Assert.assertTrue(list.size() > 0);
131 list = manager.queryServiceTemplateMapping("NS", "");
132 } catch (CatalogResourceException e2) {
133 Assert.fail("Exception" + e2.getMessage());
135 Assert.assertTrue(list.size() > 0);
137 list = manager.queryServiceTemplateMapping("", "10020");
138 } catch (CatalogResourceException e3) {
139 Assert.fail("Exception" + e3.getMessage());
141 Assert.assertTrue(list.size() > 0);
145 public void testDeleteServiceTemplateMapping() {
147 ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>();
149 manager.deleteServiceTemplateMapping("NS", "10020");
150 } catch (CatalogResourceException e1) {
151 Assert.fail("Exception" + e1.getMessage());
154 list = manager.queryServiceTemplateMapping("NS", "10020");
155 } catch (CatalogResourceException e2) {
156 Assert.fail("Exception" + e2.getMessage());
158 Assert.assertTrue(list.size() == 0);
162 public void testQueryAllServiceTemplateMapping() {
164 ArrayList<ServiceTemplateMappingData> list = new ArrayList<ServiceTemplateMappingData>();
166 list = manager.queryServiceTemplateMapping("", "");
167 } catch (CatalogResourceException e1) {
168 Assert.fail("Exception" + e1.getMessage());
170 Assert.assertTrue(list.size() > 0);