Java tutorial
/** * personium.io * Copyright 2014 FUJITSU LIMITED * * 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 com.fujitsu.dc.test.setup; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.IOException; import java.io.StringReader; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import javax.ws.rs.core.MediaType; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.junit.Test; import org.odata4j.edm.EdmSimpleType; import com.fujitsu.dc.common.auth.token.Role; import com.fujitsu.dc.common.utils.DcCoreUtils; import com.fujitsu.dc.core.DcCoreConfig; import com.fujitsu.dc.core.auth.OAuth2Helper; import com.fujitsu.dc.core.model.Box; import com.fujitsu.dc.core.model.Cell; import com.fujitsu.dc.core.model.ctl.Account; import com.fujitsu.dc.core.model.ctl.ExtCell; import com.fujitsu.dc.core.model.ctl.Relation; import com.fujitsu.dc.test.jersey.AbstractCase; import com.fujitsu.dc.test.jersey.DcRequest; import com.fujitsu.dc.test.jersey.DcResponse; import com.fujitsu.dc.test.jersey.DcRestAdapter; import com.fujitsu.dc.test.jersey.ODataCommon; import com.fujitsu.dc.test.jersey.box.odatacol.UserDataListWithNPTest; import com.fujitsu.dc.test.jersey.box.odatacol.schema.property.PropertyUtils; import com.fujitsu.dc.test.unit.core.UrlUtils; import com.fujitsu.dc.test.utils.AccountUtils; import com.fujitsu.dc.test.utils.AssociationEndUtils; import com.fujitsu.dc.test.utils.BoxUtils; import com.fujitsu.dc.test.utils.CellUtils; import com.fujitsu.dc.test.utils.DavResourceUtils; import com.fujitsu.dc.test.utils.EntityTypeUtils; import com.fujitsu.dc.test.utils.ExtRoleUtils; import com.fujitsu.dc.test.utils.Http; import com.fujitsu.dc.test.utils.RelationUtils; import com.fujitsu.dc.test.utils.ResourceUtils; import com.fujitsu.dc.test.utils.RoleUtils; import com.fujitsu.dc.test.utils.TResponse; import com.fujitsu.dc.test.utils.UserDataUtils; /** * ?. */ public class Setup extends AbstractCase { /** ????????????List??. */ List<Config> confs = new ArrayList<Config>(); List<Config> eventLogConfs = new ArrayList<Config>(); static final int NUM_ACCOUNTS = 31; static final int NUM_APP_AUTH_ACCOUNTS = 2; static final int NUM_ROLES = NUM_ACCOUNTS; static final int NUM_USERDATA = 10; /** ????. */ public static final String TEST_CELL1 = "testcell1"; /** 2????. */ public static final String TEST_CELL2 = "testcell2"; /** Schema1????. */ public static final String TEST_CELL_SCHEMA1 = "schema1"; /** Schema2????. */ public static final String TEST_CELL_SCHEMA2 = "schema2"; /** EventLog????. */ public static final String TEST_CELL_EVENTLOG = "eventLogTestCell"; /** Basic??????. */ public static final String TEST_CELL_BASIC = "basicTestSetupCell"; /** $filter??. */ public static final String TEST_CELL_FILTER = "filterTypeValidateTest"; /** >????. */ public static final String TEST_BOX1 = "box1"; /** >????. */ public static final String TEST_BOX2 = "box2"; /** >1>Odata????. */ public static final String TEST_ODATA = "setodata"; /** >1>Odata????. */ public static final String SEARCH_ODATA = "searchodata"; /** >1>Odata?EntityType. */ public static final String[] SEARCH_ENTITY_TYPES = new String[] { "string", "stringList", "int", "intList", "single", "singleList", "boolean", "booleanList", "datetime" }; /** >1>Odata>EntityType????. */ public static final String TEST_ENTITYTYPE_M1 = "entityMulti_1"; /** >1>Odata>EntityType????. */ public static final String TEST_ENTITYTYPE_MN = "entityMulti_N"; /** >1>Odata>EntityType????. */ public static final String TEST_ENTITYTYPE_MDP = "entityMaxDynamicProp"; /** ????. */ public static final String CELL_RELATION = "cellrelation"; /** VET. */ public static final String OWNER_VET = "https://example.com/test#vet"; /** HMC. */ public static final String OWNER_HMC = "https://example.com/test#hmc"; /** EVT. */ // eventLogTestCell ? public static final String OWNER_EVT = "https://example.com/test#evt"; static final double DECIMAL = 0.1; /** * . ?super????? */ public Setup() { super("com.fujitsu.dc.core.rs"); // ? List<AccountConfig> accounts = new ArrayList<AccountConfig>(); for (int i = 0; i < NUM_ACCOUNTS; i++) { AccountConfig account = new AccountConfig(); account.accountName = "account" + i; account.accountPass = "password" + i; accounts.add(account); } // BOX2 1???OdataWebDAV? BoxConfig box1 = new BoxConfig(); box1.boxName = "box1"; box1.boxSchema = UrlUtils.cellRoot("schema1"); SvcCollectionConfig svcColl = new SvcCollectionConfig(); OdataSvcCollectionConfig odataColl = new OdataSvcCollectionConfig(); DavSvcCollectionConfig davColl = new DavSvcCollectionConfig(); box1.davCol.add(davColl); box1.odataCol.add(odataColl); box1.svcCol.add(svcColl); svcColl.patch = new ProppatchConfig(); // box2? BoxConfig box2 = new BoxConfig(); box2.boxName = "box2"; box2.boxSchema = null; Config conf1 = new Config(); conf1.cellName = "testcell1"; conf1.owner = OWNER_VET; conf1.account = accounts; conf1.extRole = settingExtRole(TEST_CELL2); conf1.role = settingRole(conf1.account, conf1.extRole); conf1.box.add(box1); conf1.box.add(box2); confs.add(conf1); Config conf2 = new Config(); conf2.cellName = "testcell2"; conf2.owner = OWNER_HMC; conf2.account = accounts; conf2.extRole = settingExtRole(TEST_CELL1); conf2.role = settingRole(conf2.account, conf2.extRole); conf2.box.add(box1); conf2.box.add(box2); confs.add(conf2); // ExtCell? conf1.extCellUrl.add(UrlUtils.cellRoot(TEST_CELL2)); conf2.extCellUrl.add(UrlUtils.cellRoot(TEST_CELL1)); // RelationConfig relation1 = new RelationConfig(); relation1.name = CELL_RELATION; relation1.boxName = null; relation1.linkExtCell.add(UrlUtils.cellRoot(conf2.cellName)); conf1.relation.add(relation1); RelationConfig relation2 = new RelationConfig(); relation2.name = CELL_RELATION; relation2.boxName = null; relation2.linkExtCell.add(UrlUtils.cellRoot(conf1.cellName)); conf2.relation.add(relation2); // ?2 List<AccountConfig> appAuthAccounts = new ArrayList<AccountConfig>(); for (int i = 0; i < NUM_APP_AUTH_ACCOUNTS; i++) { AccountConfig account = new AccountConfig(); account.accountName = "account" + i; account.accountPass = "password" + i; appAuthAccounts.add(account); } // ?1 Config appAuthConf1 = new Config(); appAuthConf1.cellName = TEST_CELL_SCHEMA1; appAuthConf1.owner = OWNER_VET; appAuthConf1.account = appAuthAccounts; confs.add(appAuthConf1); // ???confidentialRole????account1 ? confidentialRole?? RoleConfig role = new RoleConfig(); role.roleName = OAuth2Helper.Key.CONFIDENTIAL_ROLE_NAME; appAuthConf1.role.add(role); role.linkAccounts.add(appAuthAccounts.get(1)); // ?2 Config appAuthConf2 = new Config(); appAuthConf2.cellName = TEST_CELL_SCHEMA2; appAuthConf2.owner = OWNER_HMC; appAuthConf2.account = appAuthAccounts; confs.add(appAuthConf2); // $filter?????????? Config filterConf = new Config(); filterConf.cellName = TEST_CELL_FILTER; filterConf.owner = null; confs.add(filterConf); // EventLog???? Config eventLogConf = new Config(); eventLogConf.cellName = TEST_CELL_EVENTLOG; eventLogConf.owner = OWNER_EVT; eventLogConfs.add(eventLogConf); // Basic?? BoxConfig basicTestBox = new BoxConfig(); basicTestBox.boxName = "box1"; basicTestBox.boxSchema = null; svcColl = new SvcCollectionConfig(); odataColl = new OdataSvcCollectionConfig(); davColl = new DavSvcCollectionConfig(); basicTestBox.davCol.add(davColl); basicTestBox.odataCol.add(odataColl); basicTestBox.svcCol.add(svcColl); svcColl.patch = new ProppatchConfig(); Config basicTestCellConf = new Config(); basicTestCellConf.cellName = TEST_CELL_BASIC; basicTestCellConf.owner = null; basicTestCellConf.account = accounts; basicTestCellConf.extRole = new ArrayList<ExtRoleConfig>(); basicTestCellConf.role = settingRole(basicTestCellConf.account, basicTestCellConf.extRole); basicTestCellConf.box.add(basicTestBox); confs.add(basicTestCellConf); } /** * . ????????????????????????? ??JUnit????????????? */ @Test public void reset() { for (Config conf : confs) { this.delete(conf); this.create(conf); } } /** * EventLog?. */ @Test public void resetEventLog() { for (Config conf : eventLogConfs) { this.delete(conf); this.createCell(conf); this.createEventLog(conf); } } /** * . ???? ??JUnit????????????? */ @Test public void destroy() { for (Config conf : confs) { this.delete(conf); } } /** * Role??. * @param ExtRoleConfig ExtRole? */ private List<RoleConfig> settingRole(List<AccountConfig> accounts, List<ExtRoleConfig> extRoles) { List<RoleConfig> roles = new ArrayList<RoleConfig>(); for (int i = 0; i < NUM_ROLES; i++) { // ? RoleConfig role = new RoleConfig(); role.roleName = "role" + i; role.linkAccounts.add(accounts.get(i)); if (extRoles != null && extRoles.size() > 0) { role.linkExtRole.add(extRoles.get(i)); } roles.add(role); } return roles; } /** * ExtRole??. * @param extCell ExtRole????CellURL */ private List<ExtRoleConfig> settingExtRole(String extCell) { List<ExtRoleConfig> extRoles = new ArrayList<ExtRoleConfig>(); for (int i = 0; i < NUM_ROLES; i++) { // ExtRole? ExtRoleConfig extRole = new ExtRoleConfig(); extRole.extRole = UrlUtils.roleResource(extCell, Box.DEFAULT_BOX_NAME, "role" + i); extRole.relationName = CELL_RELATION; extRole.relationBoxName = null; extRoles.add(extRole); } return extRoles; } /** * . * @param conf */ private void create(Config conf) { // Cell? createCell(conf); // ExtCell? createExtCell(conf); // Relation? for (RelationConfig relation : conf.relation) { RelationUtils.create(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, relation.toJson(), HttpStatus.SC_CREATED); // Relation?ExtCell?$link for (String extCell : relation.linkExtCell) { ResourceUtils.linksWithBody(conf.cellName, Relation.EDM_TYPE_NAME, relation.name, "null", ExtCell.EDM_TYPE_NAME, UrlUtils.extCellResource(conf.cellName, extCell), AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_NO_CONTENT); } } // ? for (AccountConfig account : conf.account) { this.createAccount(conf.cellName, account.accountName, account.accountPass); } // ExtRole? for (ExtRoleConfig extRole : conf.extRole) { ExtRoleUtils.create(AbstractCase.MASTER_TOKEN_NAME, conf.cellName, extRole.toJson(), HttpStatus.SC_CREATED); } // Role? for (RoleConfig role : conf.role) { String roleUrl = this.createRole(conf.cellName, role.roleName); // Role??? if (role.linkAccounts != null) { for (AccountConfig account : role.linkAccounts) { this.matchRole(conf.cellName, account.accountName, roleUrl); } } // ExtRole?Role??? if (role.linkExtRole != null) { for (ExtRoleConfig extRole : role.linkExtRole) { ResourceUtils.linksExtRoleToRole(conf.cellName, DcCoreUtils.encodeUrlComp(extRole.extRole), "'" + extRole.relationName + "'", extRole.relationBoxName, roleUrl, AbstractCase.MASTER_TOKEN_NAME); } } if ("testcell2".equals(conf.cellName)) { // ExtCell?????? // testcell2?testxell1???ExtCell?role2read????????? this.linkExtCelltoRole(DcCoreUtils.encodeUrlComp(UrlUtils.cellRoot("testcell1")), conf.cellName, roleUrl); } } // Box? for (BoxConfig box : conf.box) { this.createBox2(conf.cellName, box.boxName, box.boxSchema); // box1???ACL if ("box1".equals(box.boxName)) { // BoxACL DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "", "box/acl-authtest.txt", Setup.TEST_BOX1, ""); } } if ("testcell1".equals(conf.cellName) || "testcell2".equals(conf.cellName)) { this.createColSvc("setservice", conf.cellName); createColOdata(TEST_ODATA, conf.cellName); createColOdata(SEARCH_ODATA, conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, TEST_ODATA, "box/acl-authtest.txt", Setup.TEST_BOX1, ""); this.createColDav("setdavcol", conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "setdavcol", "box/acl-authtest.txt", Setup.TEST_BOX1, ""); this.createPatch2("setservice", conf.cellName); this.createColSvc("service_relay", conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "service_relay", "box/acl-authtest.txt", Setup.TEST_BOX1, ""); // ?? createTestCollectionSchema(conf.cellName); createMaxPropTestCollectionSchema(conf.cellName); createTestCollectionSchemaToSearchOdata(conf.cellName); // ??PUT this.resourcesPut("setdavcol/dav.txt", conf.cellName); // ? createUserDatas(conf.cellName); createUserDatasToSearchOdata(conf.cellName); // NP?ODATACollection?? createNPTestCollectionSchema(conf); // ComplexType NP??? createComplexTypeNPSchema(conf); } if (TEST_CELL_BASIC.equals(conf.cellName)) { this.createColSvc("setservice", conf.cellName); createColOdata(TEST_ODATA, conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, TEST_ODATA, "box/acl-authtest.txt", Setup.TEST_BOX1, ""); this.createColDav("setdavcol", conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "setdavcol", "box/acl-authtest.txt", Setup.TEST_BOX1, ""); this.createPatch2("setservice", conf.cellName); this.createColSvc("service_relay", conf.cellName); DavResourceUtils.setACL(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, "service_relay", "box/acl-authtest.txt", Setup.TEST_BOX1, ""); // ?? createTestCollectionSchema(conf.cellName); // ??PUT this.resourcesPut("setdavcol/dav.txt", conf.cellName); } // ????? createAccountforList(conf.cellName); // $filter?? setupFilterTestCell(conf); } /** * ??. * @param cellName ?? */ public static void createMaxPropTestCollectionSchema(String cellName) { // EntityType entityTypePost(TEST_ODATA, TEST_BOX1, TEST_ENTITYTYPE_M1, cellName); entityTypePost(TEST_ODATA, TEST_BOX1, TEST_ENTITYTYPE_MN, cellName); entityTypePost(TEST_ODATA, TEST_BOX1, TEST_ENTITYTYPE_MDP, cellName); // AssociationEnd?link? associationEndPost(TEST_ODATA, TEST_ENTITYTYPE_M1, "Multi_1_to_MaxDynamicProp", "0..1", cellName); associationEndPost(TEST_ODATA, TEST_ENTITYTYPE_MN, "Multi_N_to_MaxDynamicProp", "\\*", cellName); associationEndPost(TEST_ODATA, TEST_ENTITYTYPE_MDP, "MaxDynamicProp_to_Multi_1", "\\*", cellName); associationEndPost(TEST_ODATA, TEST_ENTITYTYPE_MDP, "MaxDynamicProp_to_Multi_N", "\\*", cellName); createAssociationEndLink(TEST_ODATA, new String[] { TEST_ENTITYTYPE_M1, TEST_ENTITYTYPE_MDP }, new String[] { "Multi_1_to_MaxDynamicProp", "MaxDynamicProp_to_Multi_1" }, cellName); createAssociationEndLink(TEST_ODATA, new String[] { TEST_ENTITYTYPE_MN, TEST_ENTITYTYPE_MDP }, new String[] { "Multi_N_to_MaxDynamicProp", "MaxDynamicProp_to_Multi_N" }, cellName); } /** * ??. * @param cellName ?? */ public static void createTestCollectionSchema(String cellName) { // EntityType entityTypePost(TEST_ODATA, TEST_BOX1, "Sales", cellName); entityTypePost(TEST_ODATA, TEST_BOX1, "SalesDetail", cellName); entityTypePost(TEST_ODATA, TEST_BOX1, "Product", cellName); entityTypePost(TEST_ODATA, TEST_BOX1, "Category", cellName); entityTypePost(TEST_ODATA, TEST_BOX1, "Supplier", cellName); entityTypePost(TEST_ODATA, TEST_BOX1, "Price", cellName); // AssociationEnd associationEndPost(TEST_ODATA, "Sales", "sales2salesDetail", "1", cellName); associationEndPost(TEST_ODATA, "SalesDetail", "salesDetail2sales", "\\*", cellName); associationEndPost(TEST_ODATA, "Product", "product2Sales", "\\*", cellName); associationEndPost(TEST_ODATA, "Sales", "sales2product", "\\*", cellName); associationEndPost(TEST_ODATA, "Product", "product2category", "1", cellName); associationEndPost(TEST_ODATA, "Category", "category2product", "1", cellName); associationEndPost(TEST_ODATA, "Supplier", "supplier2product", "0..1", cellName); associationEndPost(TEST_ODATA, "Product", "product2supplier", "1", cellName); associationEndPost(TEST_ODATA, "Sales", "sales2supplier", "0..1", cellName); associationEndPost(TEST_ODATA, "Supplier", "supplier2sales", "\\*", cellName); associationEndPost(TEST_ODATA, "Price", "price2sales", "0..1", cellName); associationEndPost(TEST_ODATA, "Sales", "sales2price", "0..1", cellName); createAssociationEndLink(TEST_ODATA, new String[] { "SalesDetail", "Sales" }, new String[] { "salesDetail2sales", "sales2salesDetail" }, cellName); createAssociationEndLink(TEST_ODATA, new String[] { "Product", "Sales" }, new String[] { "product2Sales", "sales2product" }, cellName); createAssociationEndLink(TEST_ODATA, new String[] { "Supplier", "Product" }, new String[] { "supplier2product", "product2supplier" }, cellName); createAssociationEndLink(TEST_ODATA, new String[] { "Sales", "Supplier" }, new String[] { "sales2supplier", "supplier2sales" }, cellName); createAssociationEndLink(TEST_ODATA, new String[] { "Price", "Sales" }, new String[] { "price2sales", "sales2price" }, cellName); } /** * ??. * @param cellName ?? */ public static void createTestCollectionSchemaToSearchOdata(String cellName) { // EntityType for (String entityType : SEARCH_ENTITY_TYPES) { entityTypePost(SEARCH_ODATA, TEST_BOX1, entityType, cellName); } entityTypePost(SEARCH_ODATA, TEST_BOX1, "dynamic", cellName); // Property final int count = 5; for (int i = 0; i < count; i++) { UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "string", EdmSimpleType.STRING.getFullyQualifiedTypeName(), true, null, null, false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "stringList", EdmSimpleType.STRING.getFullyQualifiedTypeName(), true, null, "List", false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "int", EdmSimpleType.INT32.getFullyQualifiedTypeName(), true, null, null, false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "intList", EdmSimpleType.INT32.getFullyQualifiedTypeName(), true, null, "List", false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "single", EdmSimpleType.SINGLE.getFullyQualifiedTypeName(), true, null, null, false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "singleList", EdmSimpleType.SINGLE.getFullyQualifiedTypeName(), true, null, "List", false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "boolean", EdmSimpleType.BOOLEAN.getFullyQualifiedTypeName(), true, null, null, false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "booleanList", EdmSimpleType.BOOLEAN.getFullyQualifiedTypeName(), true, null, "List", false, null); UserDataUtils.createProperty(cellName, TEST_BOX1, SEARCH_ODATA, "property" + i, "datetime", EdmSimpleType.DATETIME.getFullyQualifiedTypeName(), true, null, null, false, null); } } /** * ???OData?. A(0..1) - B(0..1) | C(1) - A(0..1) | D(*) - A(0..1) A(0..1) - C(1) | B(1) - C(1) | D(*) - * B(1) A(0..1) - D(*) | B(1) - D(*) | C(*) - D(*) * @param conf */ public static void createNPTestCollectionSchema(Config conf) { createColOdata(UserDataListWithNPTest.ODATA_COLLECTION, conf.cellName); // EntitySet? entityTypePost(UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, UserDataListWithNPTest.ENTITY_TYPE_A, conf.cellName); entityTypePost(UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, UserDataListWithNPTest.ENTITY_TYPE_B, conf.cellName); entityTypePost(UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, UserDataListWithNPTest.ENTITY_TYPE_C, conf.cellName); entityTypePost(UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, UserDataListWithNPTest.ENTITY_TYPE_D, conf.cellName); // AssociationEnd? associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_AB_B, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_AC_C, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_AD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BC_B, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_BC_C, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_BD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_CD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); // AssociationEnd??? createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_B }, new String[] { UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.ASSOC_AB_B }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.ASSOC_AC_C }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.ASSOC_AD_D }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_BC_B, UserDataListWithNPTest.ASSOC_BC_C }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.ASSOC_BD_D }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.ASSOC_CD_D }, conf.cellName); } /** * ???OData?. A(0..1) - B(0..1) | C(1) - A(0..1) | D(*) - A(0..1) A(0..1) - C(1) | B(1) - C(1) | D(*) - * B(1) A(0..1) - D(*) | B(1) - D(*) | C(*) - D(*) * @param conf */ public static void createComplexTypeNPSchema(Config conf) { // ComplexType? createComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_A, "complexType1stA", "etStrProp", "etComplexProp", "ct1stStrProp"); createComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_B, "complexType1stB", "etStrProp", "etComplexProp", "ct1stStrProp"); createComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_C, "complexType1stC", "etStrProp", "etComplexProp", "ct1stStrProp"); createComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_D, "complexType1stD", "etStrProp", "etComplexProp", "ct1stStrProp"); // AssociationEnd? associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_AB_B, UserDataListWithNPTest.MULTI_ZERO_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_AC_C, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_AD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BC_B, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_BC_C, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.MULTI_ONE, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_BD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.MULTI_AST, conf.cellName); associationEndPost(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_CD_D, UserDataListWithNPTest.MULTI_AST, conf.cellName); // AssociationEnd??? createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_B }, new String[] { UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.ASSOC_AB_B }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.ASSOC_AC_C }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.ASSOC_AD_D }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.ASSOC_BD_D }, conf.cellName); createAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.ASSOC_CD_D }, conf.cellName); } /** * ??Cell???. * @param cellName ?? */ @SuppressWarnings("unchecked") public static void createUserDatas(String cellName) { JSONObject body; String userDataId; // ?(10) for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("dynamicProperty", "dynamicPropertyValue" + i); body.put("sample", "sample" + i); body.put("test", "test" + i); body.put("number", i); body.put("decimal", i + DECIMAL); createUserData(cellName, "box1", TEST_ODATA, "SalesDetail", body); } // userdata001?dynamicProperty???? userDataId = "userdata001_dynamicProperty2"; body = new JSONObject(); body.put("__id", userDataId); body.put("dynamicProperty", "dynamicPropertyValue2"); body.put("sample", "sample1"); body.put("test", "test1"); body.put("decimal", 1 + DECIMAL); body.put("truth", true); createUserData(cellName, "box1", TEST_ODATA, "SalesDetail", body); // userdata001?sample???? userDataId = "userdata001_sample2"; body = new JSONObject(); body.put("__id", userDataId); body.put("dynamicProperty", "dynamicPropertyValue1"); body.put("sample", "sample2"); body.put("test", "test1"); body.put("number", null); body.put("decimal", 1 + DECIMAL); body.put("truth", false); createUserData(cellName, "box1", TEST_ODATA, "SalesDetail", body); // userdata001?test???? userDataId = "userdata001_test2"; body = new JSONObject(); body.put("__id", userDataId); body.put("dynamicProperty", "dynamicPropertyValue1"); body.put("sample", "sample1"); body.put("test", "test2"); body.put("number", 1); body.put("decimal", 1 + DECIMAL); createUserData(cellName, "box1", TEST_ODATA, "SalesDetail", body); // ? body = new JSONObject(); userDataId = "userdata100"; body.put("__id", userDataId); body.put("japanese", ""); body.put("english", "Search substringof Test"); body.put("test", "atest"); body.put("number", 1); body.put("decimal", 1 + DECIMAL); createUserDataWithDcClient(cellName, "box1", TEST_ODATA, "SalesDetail", body); body = new JSONObject(); userDataId = "userdata101"; body.put("__id", userDataId); body.put("japanese", "?"); body.put("english", "Test Substringof Search value"); body.put("test", "btest"); body.put("number", 1); body.put("decimal", 1 + DECIMAL); createUserDataWithDcClient(cellName, "box1", TEST_ODATA, "SalesDetail", body); body = new JSONObject(); userDataId = "userdata102"; body.put("__id", userDataId); body.put("japanese", "?????"); body.put("english", "test substringof search"); body.put("test", "ctest"); body.put("number", 1); body.put("decimal", 1 + DECIMAL); createUserDataWithDcClient(cellName, "box1", TEST_ODATA, "SalesDetail", body); body = new JSONObject(); userDataId = "userdata001"; body.put("__id", userDataId); int maxPropNum = DcCoreConfig.getMaxPropertyCountInEntityType(); for (int i = 0; i < maxPropNum; i++) { body.put("dynamicProperty" + i, "dynamicPropertyValue" + i); } createUserDataWithDcClient(cellName, "box1", TEST_ODATA, TEST_ENTITYTYPE_MDP, body); deleteUserData(cellName, "box1", TEST_ODATA, TEST_ENTITYTYPE_MDP, userDataId); } /** * ??Cell????. * @param cellName ?? */ @SuppressWarnings("unchecked") public static void createUserDatasToSearchOdata(String cellName) { JSONObject body; String userDataId; // ? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", ""); body.put("property3", "Value" + System.currentTimeMillis()); if (i % 2 == 0) { body.put("property4", "Value1"); } else { body.put("property4", "Value2"); } createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "string", body); } // ?? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", Arrays.asList()); body.put("property3", Arrays.asList("Value" + System.currentTimeMillis())); body.put("property4", Arrays.asList("Value" + System.currentTimeMillis(), "Value" + System.currentTimeMillis())); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "stringList", body); } // ? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", 0); body.put("property3", i + 1); body.put("property4", i - 1); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "int", body); } // ?? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", Arrays.asList()); body.put("property3", Arrays.asList(i)); body.put("property4", Arrays.asList(i - 1, i + 1)); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "intList", body); } // ?? final float num = 10.5F; for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", 0.0F); body.put("property3", (i + 1) * num); body.put("property4", (i - 1) * num); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "single", body); } // ??? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", Arrays.asList()); body.put("property3", Arrays.asList(i * num)); body.put("property4", Arrays.asList((i - 1) * num, (i + 1) * num)); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "singleList", body); } // ?? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", true); if (i % 2 == 0) { body.put("property3", false); } else { body.put("property3", true); } body.put("property4", true); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "boolean", body); } // ??? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", Arrays.asList()); body.put("property3", Arrays.asList(false)); body.put("property4", Arrays.asList(false, true)); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "booleanList", body); } // ? for (int i = 0; i < NUM_USERDATA; i++) { body = new JSONObject(); userDataId = "userdata00" + i; body.put("__id", userDataId); body.put("property1", null); body.put("property2", String.format("/Date(1398991538%03d)/", i)); body.put("property3", "/Date(1398991538550)/"); body.put("property4", "/Date(1398991538551)/"); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "datetime", body); } // ? body = new JSONObject(); userDataId = "userdata000"; body.put("__id", userDataId); body.put("property1", "Value2"); body.put("property2", 0.0); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "dynamic", body); body = new JSONObject(); userDataId = "userdata001"; body.put("__id", userDataId); body.put("property1", "Value1"); body.put("property2", 2); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "dynamic", body); body = new JSONObject(); userDataId = "userdata002"; body.put("__id", userDataId); body.put("property1", "Value1"); body.put("property2", num); createUserData(cellName, TEST_BOX1, SEARCH_ODATA, "dynamic", body); } /** * ??. * @param cellName ?? * @param boxName ?? * @param colName ?? * @param entityTypeName ?? * @param body * @return ??? */ private static DcResponse createUserDataWithDcClient(String cellName, String boxName, String colName, String entityTypeName, JSONObject body) { DcRestAdapter rest = new DcRestAdapter(); DcResponse res = null; // HashMap<String, String> requestheaders = new HashMap<String, String>(); requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN); // ? try { res = rest.post(UrlUtils.userData(cellName, boxName, colName, entityTypeName), body.toJSONString(), requestheaders); } catch (Exception e) { fail(e.getMessage()); } return res; } /** * ??. * @param cellName ?? * @param boxName ?? * @param colName ?? * @param entityTypeName ?? * @param body */ private static void createUserData(String cellName, String boxName, String colName, String entityTypeName, JSONObject body) { Http.request("box/odatacol/create.txt").with("cell", cellName).with("box", boxName) .with("collection", colName).with("entityType", entityTypeName) .with("accept", MediaType.APPLICATION_JSON).with("contentType", MediaType.APPLICATION_JSON) .with("token", "Bearer " + DcCoreConfig.getMasterToken()).with("body", body.toJSONString()) .returns().debug(); } /** * ??Cell??. * @param cellName ?? */ public static void deleteUserDatas(String cellName) { String userDataId; for (int i = 0; i < NUM_USERDATA; i++) { userDataId = "userdata00" + i; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); } userDataId = "userdata001_dynamicProperty2"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); userDataId = "userdata001_sample2"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); userDataId = "userdata001_test2"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); userDataId = "userdata100"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); userDataId = "userdata101"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); userDataId = "userdata102"; deleteUserData(cellName, "box1", TEST_ODATA, "SalesDetail", userDataId); } /** * ?. * @param cellName ?? * @param boxName ?? * @param colName ?? * @param entityTypeName ?? * @param userDataId ID */ private static void deleteUserData(String cellName, String boxName, String colName, String entityTypeName, String userDataId) { // Http.request("box/odatacol/delete.txt").with("cell", cellName).with("box", boxName) .with("collection", colName).with("entityType", entityTypeName).with("id", userDataId) .with("token", DcCoreConfig.getMasterToken()).with("ifMatch", "*").returns(); } /** * ??PUT. * @param path * @param name * @return TResponse */ private void resourcesPut(final String path, final String cellPath) { Http.request("box/dav-put.txt").with("cellPath", cellPath).with("path", path) .with("token", AbstractCase.MASTER_TOKEN_NAME).with("box", "box1").with("contentType", "text/plan") .with("source", "hoge").returns(); } /** * EntityType?POST. * @param path * @param boxName * @param name EntitySet?? * @param cellPath ?? * @return ? */ public static TResponse entityTypePost(final String path, final String boxName, final String name, final String cellPath) { TResponse tresponse = Http.request("box/entitySet-post.txt").with("cellPath", cellPath) .with("boxPath", boxName).with("odataSvcPath", path) .with("token", "Bearer " + AbstractCase.MASTER_TOKEN_NAME).with("accept", "application/xml") .with("Name", name).returns(); return tresponse; } /** * EntityType?DELETE. * @param path * @param name EntitySet?? * @param cellPath ?? * @param boxPath ?? * @return ? */ public static TResponse entityTypeDelete(final String path, final String name, final String cellPath, final String boxPath) { TResponse tresponse = Http.request("box/entitySet-delete.txt").with("cellPath", cellPath) .with("boxPath", boxPath).with("odataSvcPath", path).with("token", AbstractCase.MASTER_TOKEN_NAME) .with("accept", "application/xml").with("Name", name).returns(); return tresponse; } /** * ????EntityType?DELETE. * @param path * @param cellPath ?? * @return ? */ public static TResponse allEntityTypeDelete(final String path, final String cellPath) { // EntityType? TResponse res = Http.request("box/entitySet-query.txt").with("cellPath", cellPath) .with("odataSvcPath", path).with("token", AbstractCase.MASTER_TOKEN_NAME) .with("accept", MediaType.APPLICATION_JSON).returns(); JSONObject d = (JSONObject) res.bodyAsJson().get("d"); if (d != null) { JSONArray results = (JSONArray) d.get("results"); for (Object result : results) { JSONObject account = (JSONObject) result; String entityName = (String) account.get("Name"); entityTypeDelete(path, entityName, cellPath, TEST_BOX1); } } return res; } /** * AssociationEnd?. * @param path * @param entityTypeName ?? * @param name AssociationEnd?? * @param multiplicity ? * @param cellPath ?? * @return ? */ public static TResponse associationEndPost(final String path, final String entityTypeName, final String name, final String multiplicity, final String cellPath) { final String boxName = "box1"; TResponse tresponse = Http.request("box/associationEnd-post.txt").with("cell", cellPath) .with("box", boxName).with("odataSvcPath", path).with("entityTypeName", entityTypeName) .with("token", AbstractCase.MASTER_TOKEN_NAME).with("accept", "application/json").with("Name", name) .with("Multiplicity", multiplicity).returns(); return tresponse; } /** * AssociationEnd?. * @param path * @param entityTypeName ?? * @param name AssociationEnd?? * @param cellPath ?? * @return ? */ public static TResponse associationEndDelete(final String path, final String entityTypeName, final String name, final String cellPath) { final String boxName = "box1"; TResponse tresponse = Http.request("box/associationEnd-delete.txt").with("cell", cellPath) .with("box", boxName).with("odataSvcPath", path).with("entityTypeName", entityTypeName) .with("token", AbstractCase.MASTER_TOKEN_NAME).with("accept", "application/json").with("name", name) .with("ifMatch", "*").returns(); return tresponse; } /** * AssociationEnd?link?. * @param path * @param entityTypeName * @param name AssociationEnd?? * @param cellPath Y * @return ? */ public static TResponse createAssociationEndLink(final String path, final String[] entityTypeName, final String[] name, final String cellPath) { final String boxName = "box1"; TResponse tresponse = Http.request("box/associationEnd-createLink.txt") .with("baseUrl", UrlUtils.cellRoot(cellPath)).with("cell", cellPath).with("box", boxName) .with("odataSvcPath", path).with("entityTypeName", entityTypeName[0]) .with("linkEntityTypeName", entityTypeName[1]).with("token", AbstractCase.MASTER_TOKEN_NAME) .with("accept", "application/json").with("name", name[0]).with("linkName", name[1]).returns(); return tresponse; } /** * AssociationEnd?link. * @param path * @param entityTypeName * @param name AssociationEnd?? * @param cellPath * @param boxName ?? * @return ? */ public static TResponse deleteAssociationEndLink(final String path, final String[] entityTypeName, final String[] name, final String cellPath, final String boxName) { String key = "Name='" + name[0] + "',_EntityType.Name='" + entityTypeName[0] + "'"; String navKey = "Name='" + name[1] + "',_EntityType.Name='" + entityTypeName[1] + "'"; TResponse tresponse = Http.request("box/associationEnd-deleteLink.txt").with("cell", cellPath) .with("box", boxName).with("odataSvcPath", path).with("token", AbstractCase.MASTER_TOKEN_NAME) .with("key", key).with("navKey", navKey).returns().debug(); return tresponse; } /** * Cell?. * @param cellName Cell?? * @return Cell??? */ @SuppressWarnings("unchecked") final DcResponse createCell(final Config config) { DcRestAdapter rest = new DcRestAdapter(); DcResponse res = null; // HashMap<String, String> requestheaders = new HashMap<String, String>(); requestheaders.put(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN); // Owner??? String owner = config.owner; if (owner != null) { requestheaders.put(DcCoreUtils.HttpHeaders.X_DC_UNIT_USER, owner); } // ? JSONObject requestBody = new JSONObject(); requestBody.put("Name", config.cellName); String data = requestBody.toJSONString(); // try { res = rest.post(UrlUtils.unitCtl(Cell.EDM_TYPE_NAME), data, requestheaders); } catch (Exception e) { fail(e.getMessage()); } return res; } /** * ExtCell??. * @param conf */ private void createExtCell(Config conf) { for (String url : conf.extCellUrl) { Http.request("cell/extCell-create.txt").with("cellPath", conf.cellName) .with("token", AbstractCase.MASTER_TOKEN_NAME).with("accept", "application/xml") .with("url", url).returns(); } } /** * ?. * @param conf */ private void delete(Config conf) { // cellBulkDeletion(conf.cellName); } /** * . * @param cellName ?? */ public static void cellBulkDeletion(String cellName) { // ?API? DcRequest request = DcRequest.delete(UrlUtils.cellRoot(cellName)); request.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).header("X-Dc-Recursive", "true"); request(request); } /** * ?. * @param cellName ?? */ public static void deleteMaxPropTestCollectionSchema(String cellName) { // AssociationEnd?$links deleteAssociationEndLink(TEST_ODATA, new String[] { TEST_ENTITYTYPE_M1, TEST_ENTITYTYPE_MDP }, new String[] { "Multi_1_to_MaxDynamicProp", "MaxDynamicProp_to_Multi_1" }, cellName, TEST_BOX1); deleteAssociationEndLink(TEST_ODATA, new String[] { TEST_ENTITYTYPE_MN, TEST_ENTITYTYPE_MDP }, new String[] { "Multi_N_to_MaxDynamicProp", "MaxDynamicProp_to_Multi_N" }, cellName, TEST_BOX1); // AssociationEnd? associationEndDelete(TEST_ODATA, TEST_ENTITYTYPE_M1, "Multi_1_to_MaxDynamicProp", cellName); associationEndDelete(TEST_ODATA, TEST_ENTITYTYPE_MN, "Multi_N_to_MaxDynamicProp", cellName); associationEndDelete(TEST_ODATA, TEST_ENTITYTYPE_MDP, "MaxDynamicProp_to_Multi_1", cellName); associationEndDelete(TEST_ODATA, TEST_ENTITYTYPE_MDP, "MaxDynamicProp_to_Multi_N", cellName); entityTypeDelete(TEST_ODATA, TEST_ENTITYTYPE_MDP, cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, TEST_ENTITYTYPE_MN, cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, TEST_ENTITYTYPE_M1, cellName, TEST_BOX1); } /** * ?. * @param cellName ?? */ public static void deleteTestCollectionSchema(String cellName) { deleteAssociationEndLink(TEST_ODATA, new String[] { "SalesDetail", "Sales" }, new String[] { "salesDetail2sales", "sales2salesDetail" }, cellName, TEST_BOX1); deleteAssociationEndLink(TEST_ODATA, new String[] { "Product", "Sales" }, new String[] { "product2Sales", "sales2product" }, cellName, TEST_BOX1); deleteAssociationEndLink(TEST_ODATA, new String[] { "Supplier", "Product" }, new String[] { "supplier2product", "product2supplier" }, cellName, TEST_BOX1); deleteAssociationEndLink(TEST_ODATA, new String[] { "Sales", "Supplier" }, new String[] { "sales2supplier", "supplier2sales" }, cellName, TEST_BOX1); deleteAssociationEndLink(TEST_ODATA, new String[] { "Price", "Sales" }, new String[] { "price2sales", "sales2price" }, cellName, TEST_BOX1); associationEndDelete(TEST_ODATA, "Sales", "sales2salesDetail", cellName); associationEndDelete(TEST_ODATA, "SalesDetail", "salesDetail2sales", cellName); associationEndDelete(TEST_ODATA, "Product", "product2Sales", cellName); associationEndDelete(TEST_ODATA, "Sales", "sales2product", cellName); associationEndDelete(TEST_ODATA, "Product", "product2category", cellName); associationEndDelete(TEST_ODATA, "Category", "category2product", cellName); associationEndDelete(TEST_ODATA, "Supplier", "supplier2product", cellName); associationEndDelete(TEST_ODATA, "Product", "product2supplier", cellName); associationEndDelete(TEST_ODATA, "Sales", "sales2supplier", cellName); associationEndDelete(TEST_ODATA, "Supplier", "supplier2sales", cellName); associationEndDelete(TEST_ODATA, "Sales", "sales2price", cellName); associationEndDelete(TEST_ODATA, "Price", "price2sales", cellName); entityTypeDelete(TEST_ODATA, "Category", cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, "Price", cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, "Product", cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, "Sales", cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, "SalesDetail", cellName, TEST_BOX1); entityTypeDelete(TEST_ODATA, "Supplier", cellName, TEST_BOX1); } /** * NPOData. * @param conf */ public static void deleteComplexTypeNPSchema(Config conf) { // AssociationEnd?$links String key = "Name='" + UserDataListWithNPTest.ASSOC_AB_A + "',_EntityType.Name='" + UserDataListWithNPTest.CT_ENTITY_TYPE_A + "'"; String navKey = "Name='" + UserDataListWithNPTest.ASSOC_AB_B + "',_EntityType.Name='" + UserDataListWithNPTest.CT_ENTITY_TYPE_B + "'"; AssociationEndUtils.deleteLink(conf.cellName, UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, key, navKey, -1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_B }, new String[] { UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.ASSOC_AB_B }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.ASSOC_AC_C }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.ASSOC_AD_D }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.ASSOC_BD_D }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.CT_ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.ASSOC_CD_D }, conf.cellName, TEST_BOX1); // AssociationEnd? associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AB_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AC_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AD_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_AB_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_AC_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_AD_D, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BC_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_BC_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BD_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_BD_D, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_CD_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_CD_D, conf.cellName); // ComplexType? deleteComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_A, "complexType1stA", "etStrProp", "etComplexProp", "ct1stStrProp"); deleteComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_B, "complexType1stB", "etStrProp", "etComplexProp", "ct1stStrProp"); deleteComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_C, "complexType1stC", "etStrProp", "etComplexProp", "ct1stStrProp"); deleteComplexTypeSchema(conf, UserDataListWithNPTest.CT_ENTITY_TYPE_D, "complexType1stD", "etStrProp", "etComplexProp", "ct1stStrProp"); // EntitySet? entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_A, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_B, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_C, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.CT_ENTITY_TYPE_D, conf.cellName, TEST_BOX1); } /** * NP?ODATACollection?. * @param conf */ public static void deleteNPTestCollection(Config conf) { // AssociationEnd?$links String key = "Name='" + UserDataListWithNPTest.ASSOC_AB_A + "',_EntityType.Name='" + UserDataListWithNPTest.ENTITY_TYPE_A + "'"; String navKey = "Name='" + UserDataListWithNPTest.ASSOC_AB_B + "',_EntityType.Name='" + UserDataListWithNPTest.ENTITY_TYPE_B + "'"; AssociationEndUtils.deleteLink(conf.cellName, UserDataListWithNPTest.ODATA_COLLECTION, TEST_BOX1, key, navKey, -1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_B }, new String[] { UserDataListWithNPTest.ASSOC_AB_A, UserDataListWithNPTest.ASSOC_AB_B }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_AC_A, UserDataListWithNPTest.ASSOC_AC_C }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_AD_A, UserDataListWithNPTest.ASSOC_AD_D }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ENTITY_TYPE_C }, new String[] { UserDataListWithNPTest.ASSOC_BC_B, UserDataListWithNPTest.ASSOC_BC_C }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_BD_B, UserDataListWithNPTest.ASSOC_BD_D }, conf.cellName, TEST_BOX1); deleteAssociationEndLink(UserDataListWithNPTest.ODATA_COLLECTION, new String[] { UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ENTITY_TYPE_D }, new String[] { UserDataListWithNPTest.ASSOC_CD_C, UserDataListWithNPTest.ASSOC_CD_D }, conf.cellName, TEST_BOX1); // AssociationEnd? associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AB_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AC_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, UserDataListWithNPTest.ASSOC_AD_A, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_AB_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_AC_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_AD_D, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BC_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_BC_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, UserDataListWithNPTest.ASSOC_BD_B, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_BD_D, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, UserDataListWithNPTest.ASSOC_CD_C, conf.cellName); associationEndDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, UserDataListWithNPTest.ASSOC_CD_D, conf.cellName); // EntitySet? entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_A, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_B, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_C, conf.cellName, TEST_BOX1); entityTypeDelete(UserDataListWithNPTest.ODATA_COLLECTION, UserDataListWithNPTest.ENTITY_TYPE_D, conf.cellName, TEST_BOX1); // ODATACollection? deleteCol(UserDataListWithNPTest.ODATA_COLLECTION, conf.cellName); } /** * ?. * @param path * @param cellPath ?? */ public static void deleteCol(final String path, final String cellPath) { Http.request("box/delete-col.txt").with("cellPath", cellPath).with("path", path) .with("token", AbstractCase.MASTER_TOKEN_NAME).returns(); } /** * ?. * @param cellName ?? * @param name ?? * @param pass * @return ???Account?URL */ private String createAccount(final String cellName, final String name, final String pass) { DcRequest req = DcRequest.post(UrlUtils.cellCtl(cellName, Account.EDM_TYPE_NAME)); req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN) .header(DcCoreUtils.HttpHeaders.X_DC_CREDENTIAL, pass).addJsonBody("Name", name); DcResponse res = request(req); assertEquals(HttpStatus.SC_CREATED, res.getStatusCode()); String accLocHeader = res.getFirstHeader(HttpHeaders.LOCATION); assertNotNull(accLocHeader); return accLocHeader; } /** * ????. * ?????????LastAuthenticated?????? * @param cellName */ private void createAccountforList(String cellName) { final int accountNum = 10; final int noTimeAccountNum = 5; String roleName = "accountListViaNPRoleName"; // Account?????Role?? RoleUtils.create(cellName, AbstractCase.MASTER_TOKEN_NAME, roleName, HttpStatus.SC_CREATED); // 1 for (int i = 1; i <= accountNum; i++) { String userName = String.format("LastAuthenticatedListUser%03d", i); String body = "{\"Name\":\"" + userName + "\", \"LastAuthenticated\":\"/Date(" + System.currentTimeMillis() + ")/\"}"; AccountUtils.createViaNPNonCredential(cellName, AbstractCase.MASTER_TOKEN_NAME, "Role", roleName, body, HttpStatus.SC_CREATED); } // 2 for (int i = accountNum + 1; i < accountNum * 2; i++) { String userName = String.format("LastAuthenticatedListUser%03d", i); String body = "{\"Name\":\"" + userName + "\", \"LastAuthenticated\":\"/Date(" + System.currentTimeMillis() + ")/\"}"; AccountUtils.createViaNPNonCredential(cellName, AbstractCase.MASTER_TOKEN_NAME, "Role", roleName, body, HttpStatus.SC_CREATED); } // ???? for (int i = accountNum * 2 + 1; i < accountNum * 2 + noTimeAccountNum; i++) { String userName = String.format("LastAuthenticatedListUser%03d", i); String body = "{\"Name\":\"" + userName + "\"}"; AccountUtils.createViaNPNonCredential(cellName, AbstractCase.MASTER_TOKEN_NAME, "Role", roleName, body, HttpStatus.SC_CREATED); } } /** * ?. * @param cellName ?? * @param testRoleName * @return ???Role?URL */ private String createRole(final String cellName, final String testRoleName) { DcRequest req = DcRequest.post(UrlUtils.cellCtl(cellName, Role.EDM_TYPE_NAME)); req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody("Name", testRoleName) .addJsonBody("_Box.Name", null); DcResponse res = request(req); assertEquals(HttpStatus.SC_CREATED, res.getStatusCode()); String roleLocHeader = res.getFirstHeader(HttpHeaders.LOCATION); assertNotNull(roleLocHeader); return roleLocHeader; } /** * ????. * @param cellName ?? * @param testRoleName * @return ???Role?URL */ private void matchRole(final String cellName, final String accountName, final String roleUrl) { DcRequest req = DcRequest.post(UrlUtils.accountLinks(cellName, accountName)); req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody("uri", roleUrl); DcResponse res = request(req); assertEquals(HttpStatus.SC_NO_CONTENT, res.getStatusCode()); } /** * BOX?. * @param cellName ?? * @param boxName ?? * @param boxSchema * @return boxURL */ private String createBox2(final String cellName, final String boxName, final String boxSchema) { DcRequest req = DcRequest.post(UrlUtils.cellCtl(cellName, Box.EDM_TYPE_NAME)); req.header(HttpHeaders.AUTHORIZATION, BEARER_MASTER_TOKEN).addJsonBody("Name", boxName); if (boxSchema != null) { req.addJsonBody("Schema", boxSchema); } DcResponse res = request(req); assertEquals(HttpStatus.SC_CREATED, res.getStatusCode()); String url = res.getFirstHeader(HttpHeaders.LOCATION); assertNotNull(url); return url; } /** * ?. * @param cellName ?? * @param path ?? * @return boxURL */ private TResponse createColSvc(final String path, final String cellPath) { TResponse tresponseWebDav = null; // DAV?? tresponseWebDav = Http.request("box/mkcol-service.txt").with("cellPath", cellPath).with("path", path) .with("token", AbstractCase.MASTER_TOKEN_NAME).returns(); tresponseWebDav.statusCode(HttpStatus.SC_CREATED); return tresponseWebDav; } /** * Dav?. * @param cellName ?? * @param path ?? * @return boxURL */ private TResponse createColDav(final String path, final String cellPath) { TResponse tresponseWebDav = null; // DAV?? tresponseWebDav = Http.request("box/mkcol-normal.txt").with("cellPath", cellPath).with("path", path) .with("token", AbstractCase.MASTER_TOKEN_NAME).returns(); tresponseWebDav.statusCode(HttpStatus.SC_CREATED); return tresponseWebDav; } /** * Odata?. * @param path ?? * @param cellPath ?? * @return boxURL */ public static TResponse createColOdata(final String path, final String cellPath) { TResponse tresponseWebDav = null; // DAV?? tresponseWebDav = Http.request("box/mkcol-odata.txt").with("cellPath", cellPath).with("boxPath", "box1") .with("path", path).with("token", AbstractCase.MASTER_TOKEN_NAME).returns(); tresponseWebDav.statusCode(HttpStatus.SC_CREATED); return tresponseWebDav; } /** * PROPPATCH?. * @param path ?? * @return boxURL */ private TResponse createPatch2(final String path, final String cellPath) { TResponse tresponseWebDav = null; tresponseWebDav = Http.request("box/proppatch-class.txt").with("path", path) .with("token", AbstractCase.MASTER_TOKEN_NAME).with("cellPath", cellPath) .with("name1", "Test User1").with("src1", "hoge").with("name2", "Test User2").with("src2", "fuga") .with("name3", "Test User3").with("src3", "boy").returns(); tresponseWebDav.statusCode(HttpStatus.SC_MULTI_STATUS); return tresponseWebDav; } /** * ExtCell??????. * @param cellName ?????? * @param cellPath ? * @param roleUrl ????URL * @return */ private TResponse linkExtCelltoRole(final String cellName, final String cellPath, final String roleUrl) { TResponse tresponseWebDav = null; // DAV?? tresponseWebDav = Http.request("cell/link-extCell-role.txt").with("cellPath", cellPath) .with("cellName", cellName).with("token", AbstractCase.MASTER_TOKEN_NAME).with("roleUrl", roleUrl) .returns(); tresponseWebDav.statusCode(HttpStatus.SC_NO_CONTENT); return tresponseWebDav; } /** * ?. */ private class Config { private String cellName = ""; private List<String> extCellUrl = new ArrayList<String>(); private String owner = null; private List<AccountConfig> account = new ArrayList<AccountConfig>(); private List<RoleConfig> role = new ArrayList<RoleConfig>(); private List<BoxConfig> box = new ArrayList<BoxConfig>(); private List<RelationConfig> relation = new ArrayList<RelationConfig>(); private List<ExtRoleConfig> extRole = new ArrayList<ExtRoleConfig>(); } /** * ?. */ private class AccountConfig { private String accountName = ""; private String accountPass = ""; } /** * ?. */ private class RoleConfig { private String roleName = ""; private List<AccountConfig> linkAccounts = new ArrayList<AccountConfig>(); private List<ExtRoleConfig> linkExtRole = new ArrayList<ExtRoleConfig>(); } /** * BOX?. */ private class BoxConfig { private String boxName = ""; private String boxSchema = ""; private List<DavSvcCollectionConfig> davCol = new ArrayList<DavSvcCollectionConfig>(); private List<OdataSvcCollectionConfig> odataCol = new ArrayList<OdataSvcCollectionConfig>(); private List<SvcCollectionConfig> svcCol = new ArrayList<SvcCollectionConfig>(); } /** * ?. */ @SuppressWarnings("unused") private class SvcCollectionConfig { private String colName = ""; private ProppatchConfig patch = null; } /** * Dav?. */ @SuppressWarnings("unused") private class DavSvcCollectionConfig { private String colName = ""; private ProppatchConfig patch = null; } /** * Odata?. */ @SuppressWarnings("unused") private class OdataSvcCollectionConfig { private String colName = ""; private ProppatchConfig patch = null; } /** * PROPPATCH?. */ @SuppressWarnings("unused") private class ProppatchConfig { private String patchName = ""; } /** * ?. */ private class RelationConfig { private String name = ""; private String boxName = ""; private List<String> linkExtCell = new ArrayList<String>(); @SuppressWarnings("unchecked") public JSONObject toJson() { JSONObject relationJson = new JSONObject(); relationJson.put("Name", name); relationJson.put("_Box.Name", boxName); return relationJson; } } /** * ExtRole?. */ private class ExtRoleConfig { private String extRole = ""; private String relationName = ""; private String relationBoxName = ""; @SuppressWarnings("unchecked") public JSONObject toJson() { JSONObject extRoleJson = new JSONObject(); extRoleJson.put("ExtRole", extRole); extRoleJson.put("_Relation.Name", relationName); extRoleJson.put("_Relation._Box.Name", relationBoxName); return extRoleJson; } } /** * ComplexType??. * @param conf * @param entityTypeName ?? * @param complexTypeName ?? * @param propertyName ?? * @param complexTypePropertyName ?? * @param innnerComplexTypePropertyName ?? */ protected static void createComplexTypeSchema(Config conf, String entityTypeName, String complexTypeName, String propertyName, String complexTypePropertyName, String innnerComplexTypePropertyName) { // EntityType? EntityTypeUtils.create(conf.cellName, AbstractCase.MASTER_TOKEN_NAME, UserDataListWithNPTest.ODATA_COLLECTION, entityTypeName, HttpStatus.SC_CREATED); // ComplexType? UserDataUtils.createComplexType(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, complexTypeName); // Property? UserDataUtils.createProperty(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, propertyName, entityTypeName, EdmSimpleType.STRING.getFullyQualifiedTypeName(), false, null, null, false, null); UserDataUtils.createProperty(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, complexTypePropertyName, entityTypeName, complexTypeName, false, null, null, false, null); // complexTypeProperty? UserDataUtils.createComplexTypeProperty(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, innnerComplexTypePropertyName, complexTypeName, EdmSimpleType.STRING.getFullyQualifiedTypeName(), false, null, null); } /** * ComplexType?. * @param conf * @param entityTypeName ?? * @param complexTypeName ?? * @param propertyName ?? * @param complexTypePropertyName ?? * @param innnerComplexTypePropertyName ?? */ public static void deleteComplexTypeSchema(Config conf, String entityTypeName, String complexTypeName, String propertyName, String complexTypePropertyName, String innnerComplexTypePropertyName) { String ctlocationUrl = UrlUtils.complexType(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, complexTypeName); String propStrlocationUrl = UrlUtils.property(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, propertyName, entityTypeName); String propCtlocationUrl = UrlUtils.property(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, complexTypePropertyName, entityTypeName); String ctplocationUrl = UrlUtils.complexTypeProperty(conf.cellName, TEST_BOX1, UserDataListWithNPTest.ODATA_COLLECTION, innnerComplexTypePropertyName, complexTypeName); // ???Property ODataCommon.deleteOdataResource(propStrlocationUrl); ODataCommon.deleteOdataResource(propCtlocationUrl); // ???ComplexTypeProperty ODataCommon.deleteOdataResource(ctplocationUrl); // ???ComplexType ODataCommon.deleteOdataResource(ctlocationUrl); } /** * EventLog?????. <br /> * 3KByte 36,000 = 108,000KByte ?????? * @param conf */ public void createEventLog(Config conf) { final int itemCodeNum = 1024; final int loopCount = 36000; String jsonBase = "{\\\"level\\\":\\\"INFO\\\"," + "\\\"action\\\":\\\"%1$s\\\",\\\"object\\\":\\\"%1$s\\\",\\\"result\\\":\\\"%1$s\\\"}"; StringBuilder buf = new StringBuilder(); for (int i = 0; i < itemCodeNum; i++) { buf.append("a"); } String jsonBody = String.format(jsonBase, buf.toString()); for (int i = 0; i < loopCount; i++) { CellUtils.event(AbstractCase.MASTER_TOKEN_NAME, HttpStatus.SC_OK, conf.cellName, jsonBody); } } /** * $filter??OData??. * @param conf ? */ private void setupFilterTestCell(Config conf) { if (TEST_CELL_FILTER.equals(conf.cellName)) { String token = AbstractCase.MASTER_TOKEN_NAME; String box = "box"; String col = "odata"; BoxUtils.create(TEST_CELL_FILTER, "box", token); DavResourceUtils.createODataCollection(token, HttpStatus.SC_CREATED, TEST_CELL_FILTER, box, col); // ? EntityTypeUtils.create(TEST_CELL_FILTER, token, box, col, "entity", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "string", "Edm.String", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "int32", "Edm.Int32", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "single", "Edm.Single", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "double", "Edm.Double", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "boolean", "Edm.Boolean", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "datetime", "Edm.DateTime", "None", HttpStatus.SC_CREATED); createFilterTestProperty("entity", "int32_list", "Edm.Int32", "List", HttpStatus.SC_CREATED); createFilterTypeValidateTestUserData(); // EntityTypeUtils.create(TEST_CELL_FILTER, token, box, col, "filterlist", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "string", "Edm.String", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "int32", "Edm.Int32", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "single", "Edm.Single", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "double", "Edm.Double", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "boolean", "Edm.Boolean", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "datetime", "Edm.DateTime", "None", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "string_list", "Edm.String", "List", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "int32_list", "Edm.Int32", "List", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "single_list", "Edm.Single", "List", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "double_list", "Edm.Double", "List", HttpStatus.SC_CREATED); createFilterTestProperty("filterlist", "boolean_list", "Edm.Boolean", "List", HttpStatus.SC_CREATED); createFilterTestUserData("filterlist"); } } /** * $filter??EntityType??Property?. * @param entity EntityType?? * @param name ?? * @param type ?(ex. "Edm.Single") * @param kind CollectionKind? * @param code ?HTTP */ private void createFilterTestProperty(String entity, String name, String type, String kind, int code) { PropertyUtils.create(AbstractCase.BEARER_MASTER_TOKEN, TEST_CELL_FILTER, "box", "odata", entity, name, type, true, null, kind, false, null, code); } /** * $filter?EntityType?OData?. */ private void createFilterTypeValidateTestUserData() { final String token = AbstractCase.MASTER_TOKEN_NAME; try { String bodyStr1 = "{\"__id\":\"id1\"," + "\"string\":\"string_data\",\"int32\":1111,\"single\":1111.11,\"double\":1111.1111111," + "\"boolean\":true,\"datetime\":\"/Date(1420589956172)/\"," + "\"d_string\":\"string_value\",\"d_int32\":2222,\"d_single\":2222.22,\"d_double\":2222.2222222," + "\"d_boolean\":true,\"d_datetime\":\"/Date(1410689956172)/\"," + "\"int32_list\":[1,2,3,4,5]}"; JSONObject body1 = (JSONObject) new JSONParser().parse(new StringReader(bodyStr1)); UserDataUtils.create(token, HttpStatus.SC_CREATED, body1, TEST_CELL_FILTER, "box", "odata", "entity"); String bodyStr2 = "{\"__id\":\"id2\"," + "\"string\":\"string data\",\"int32\":1111,\"single\":1111.0,\"double\":1111.0," + "\"boolean\":false,\"datetime\":\"/Date(1420589956173)/\"," + "\"d_string\":\"string value\",\"d_int32\":2222,\"d_single\":2222.0,\"d_double\":2222.0," + "\"d_boolean\":false,\"d_datetime\":\"/Date(1410689956172)/\"," + "\"int32_list\":[3,4,5,6,7]}"; JSONObject body2 = (JSONObject) new JSONParser().parse(new StringReader(bodyStr2)); UserDataUtils.create(token, HttpStatus.SC_CREATED, body2, TEST_CELL_FILTER, "box", "odata", "entity"); } catch (IOException e) { fail(e.getMessage()); } catch (ParseException e) { fail(e.getMessage()); } } /** * $filter?EntityType?OData?. * @param entity EntityType?? */ private void createFilterTestUserData(String entity) { final String token = AbstractCase.MASTER_TOKEN_NAME; final int userDataNum = 10; final int intData = 1111; final BigDecimal singleData = new BigDecimal(1111.11); final BigDecimal doubleData = new BigDecimal(1111111.1111111d); final long dateTimeData = 1410689956172L; final int dateTimeOffset = 1000000; try { for (int i = 0; i < userDataNum; i++) { StringBuilder sbuf = new StringBuilder(); sbuf.append(String.format("{\"__id\":\"id_%04d\",", i)); sbuf.append(String.format("\"string\":\"string %s\",", String.format("%04d", i))); sbuf.append(String.format("\"int32\":%d,", intData * i)); sbuf.append(String.format("\"single\":%f,", singleData.multiply(new BigDecimal(i)))); sbuf.append(String.format("\"double\":%f,", doubleData.multiply(new BigDecimal(i)))); sbuf.append(String.format("\"boolean\":%b,", i % 2 == 0)); sbuf.append(String.format("\"datetime\":\"/Date(%d)/\",", dateTimeData + i * dateTimeOffset)); sbuf.append(String.format("\"string_list\":%s,", getStringArray(i))); sbuf.append(String.format("\"int32_list\":%s,", getIntgerArray(i))); sbuf.append(String.format("\"single_list\":%s,", getFloatArray(i))); sbuf.append(String.format("\"double_list\":%s,", getDoubleArray(i))); sbuf.append(String.format("\"boolean_list\":%s,", getBooleanArray(i))); sbuf.append(String.format("}", i % 2 == 0)); JSONObject body = (JSONObject) new JSONParser().parse(new StringReader(sbuf.toString())); UserDataUtils.create(token, HttpStatus.SC_CREATED, body, TEST_CELL_FILTER, "box", "odata", entity); } } catch (IOException e) { fail(e.getMessage()); } catch (ParseException e) { fail(e.getMessage()); } } /** * $filter??(Edm.String)????. * @param index ??? * @return ??? */ private String getStringArray(int index) { StringBuilder sbuf = new StringBuilder("["); for (int i = 0; i < index; i++) { if (i == 0) { sbuf.append(String.format("\"array %04d\"", i)); } else { sbuf.append(String.format(",\"array %04d\"", i)); } } sbuf.append("]"); return sbuf.toString(); } /** * $filter??(Edm.Int32)????. * @param index ??? * @return ??? */ private String getIntgerArray(int index) { final int intData = 1111; StringBuilder sbuf = new StringBuilder("["); for (int i = 0; i < index; i++) { if (i == 0) { sbuf.append(String.format("%d", intData * i)); } else { sbuf.append(String.format(",%d", intData * i)); } } sbuf.append("]"); return sbuf.toString(); } /** * $filter??(Edm.Single)????. * @param index ??? * @return ??? */ private String getFloatArray(int index) { final BigDecimal singleData = new BigDecimal(1111.11); StringBuilder sbuf = new StringBuilder("["); for (int i = 0; i < index; i++) { if (i == 0) { sbuf.append(String.format("%f", singleData.multiply(new BigDecimal(i)))); } else { sbuf.append(String.format(",%f", singleData.multiply(new BigDecimal(i)))); } } sbuf.append("]"); return sbuf.toString(); } /** * $filter??(Edm.Double)????. * @param index ??? * @return ??? */ private String getDoubleArray(int index) { final BigDecimal doubleData = new BigDecimal(1111111.1111111d); StringBuilder sbuf = new StringBuilder("["); for (int i = 0; i < index; i++) { if (i == 0) { sbuf.append(String.format("%f", doubleData.multiply(new BigDecimal(i)))); } else { sbuf.append(String.format(",%f", doubleData.multiply(new BigDecimal(i)))); } } sbuf.append("]"); return sbuf.toString(); } /** * $filter??(Edm.Boolean)????. * @param index ??? * @return ??? */ private String getBooleanArray(int index) { boolean value = (index % 2 == 0); StringBuilder sbuf = new StringBuilder("["); for (int i = 0; i < index; i++) { if (i == 0) { sbuf.append(String.format("%b", value)); } else { sbuf.append(String.format(",%b", value)); } } sbuf.append("]"); return sbuf.toString(); } }