@Override protected CubeDesc initEntityAfterReload(CubeDesc cubeDesc, String resourceName) { if (cubeDesc.isDraft()) throw new IllegalArgumentException(String.format(Locale.ROOT, CUBE_SHOULD_NOT_BE_DRAFT_MSG, cubeDesc.getName())); try { cubeDesc.init(config); } catch (Exception e) { logger.warn(String.format(Locale.ROOT, BROKEN_CUBE_MSG, cubeDesc.resourceName()), e); cubeDesc.addError(e.toString()); } return cubeDesc; } };
@Test(expected = IllegalStateException.class) public void testValidateMeasureNamesDuplicated() throws IOException { File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/ssb.json"); CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); MeasureDesc measureDescDuplicated = desc.getMeasures().get(1); List<MeasureDesc> newMeasures = Lists.newArrayList(desc.getMeasures()); newMeasures.add(measureDescDuplicated); desc.setMeasures(newMeasures); desc.init(config); } }
@Test public void testCombinationIntOverflow() throws Exception { for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA, "cube_desc").listFiles()) { if (f.getName().endsWith(".bad")) { String path = f.getPath(); f.renameTo(new File(path.substring(0, path.length() - 4))); } } thrown.expect(TooManyCuboidException.class); getTestConfig().clearManagers(); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()) .getCubeDesc("ut_cube_desc_combination_int_overflow"); cubeDesc.init(getTestConfig()); }
@Test public void testGoodDesc() throws IOException { DictionaryRule rule = new DictionaryRule(); for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/").listFiles()) { if (!f.getName().endsWith("json")) { continue; } CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); desc.init(config); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); assertTrue(vContext.getResults().length == 0); } }
@Test public void testTooManyRowkeys() throws Exception { File metaFile = new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA, "cube_desc/ut_78_rowkeys.json.bad"); Assert.assertTrue(metaFile.exists()); String path = metaFile.getPath(); metaFile.renameTo(new File(path.substring(0, path.length() - 4))); thrown.expect(IllegalArgumentException.class); thrown.expectMessage( "Too many rowkeys (78) in CubeDesc, please try to reduce dimension number or adopt derived dimensions"); getTestConfig().clearManagers(); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc("ut_78_rowkeys"); cubeDesc.init(getTestConfig()); }
@Test public void testGoodDesc() throws IOException { AggregationGroupRule rule = getAggregationGroupRule(); for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA + "/cube_desc/").listFiles()) { if (!f.getName().endsWith("json")) { continue; } CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); desc.init(getTestConfig()); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); //vContext.print(System.out); assertTrue(vContext.getResults().length == 0); } }
@Test public void testBadInit3() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Aggregation group 1 'includes' dimensions not include all the dimensions:"); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); String[] temp = Arrays.asList(cubeDesc.getAggregationGroups().get(0).getIncludes()).subList(0, 3) .toArray(new String[3]); cubeDesc.getAggregationGroups().get(0).setIncludes(temp); cubeDesc.init(getTestConfig()); }
@Test public void testGoodDesc() throws IOException { FunctionRule rule = new FunctionRule(); File f = new File(LocalFileMetadataTestCase.LOCALMETA_TEST_DATA + "/cube_desc/ssb.json"); CubeDesc desc = JsonUtil.readValue(new FileInputStream(f), CubeDesc.class); desc.init(config); ValidateContext vContext = new ValidateContext(); rule.validate(desc, vContext); vContext.print(System.out); assertTrue(vContext.getResults().length == 0); }
@Test public void testGoodInit() throws Exception { CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.init(getTestConfig()); }
@Test public void testBadInit5() throws Exception { CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().mandatoryDims = new String[] { SELLER_ID, META_CATEG_NAME }; cubeDesc.init(getTestConfig()); }
@Test public void testValidateNotifyList() throws Exception { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Email [test] is not validation."); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); List<String> notify = Lists.newArrayList(); notify.add("test"); cubeDesc.setNotifyList(notify); cubeDesc.validateNotifyList(); cubeDesc.init(getTestConfig()); }
@Test public void testBadInit6() throws Exception { CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().mandatoryDims = new String[] { SELLER_ID, LSTG_FORMAT_NAME }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit1() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("AggregationGroup incomplete"); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); String[] temp = null; cubeDesc.getAggregationGroups().get(0).setIncludes(temp); cubeDesc.init(getTestConfig()); }
@Test public void testBadInit7() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Aggregation group 1 require at least 2 dimensions in a joint"); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { new String[] { LSTG_FORMAT_NAME } }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit2() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("AggregationGroup incomplete"); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); SelectRule temp = null; cubeDesc.getAggregationGroups().get(0).setSelectRule(temp); cubeDesc.init(getTestConfig()); }
@Test public void testBadInit11() throws Exception { thrown.expect(IllegalStateException.class); thrown.expectMessage("Aggregation group 1 require at least 2 dimensions in a hierarchy."); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchyDims = new String[][] { new String[] { META_CATEG_NAME } }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit8() throws Exception { String[] strs = new String[] { CATEG_LVL2_NAME, META_CATEG_NAME }; thrown.expect(IllegalStateException.class); thrown.expectMessage( "Aggregation group 1 hierarchy dimensions overlap with joint dimensions: " + sortStrs(strs)); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { new String[] { META_CATEG_NAME, CATEG_LVL2_NAME } }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit9() throws Exception { String[] strs = new String[] { LSTG_FORMAT_NAME, META_CATEG_NAME }; thrown.expect(IllegalStateException.class); thrown.expectMessage( "Aggregation group 1 hierarchy dimensions overlap with joint dimensions: " + sortStrs(strs)); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchyDims = new String[][] { new String[] { META_CATEG_NAME, CATEG_LVL2_NAME, CATEG_LVL3_NAME }, new String[] { LSTG_FORMAT_NAME, LSTG_SITE_ID } }; cubeDesc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { new String[] { META_CATEG_NAME, LSTG_FORMAT_NAME } }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit10() throws Exception { String[] strs = new String[] { LSTG_FORMAT_NAME, LSTG_SITE_ID }; thrown.expect(IllegalStateException.class); thrown.expectMessage("Aggregation group 1 a dimension exist in more than one joint: " + sortStrs(strs)); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().jointDims = new String[][] { new String[] { LSTG_FORMAT_NAME, LSTG_SITE_ID, SLR_SEGMENT_CD }, new String[] { LSTG_FORMAT_NAME, LSTG_SITE_ID, LEAF_CATEG_ID } }; cubeDesc.init(getTestConfig()); }
@Test public void testBadInit12() throws Exception { String[] strs = new String[] { CATEG_LVL2_NAME, META_CATEG_NAME }; thrown.expect(IllegalStateException.class); thrown.expectMessage("Aggregation group 1 a dimension exist in more than one hierarchy: " + sortStrs(strs)); CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC); cubeDesc.getAggregationGroups().get(0).getSelectRule().hierarchyDims = new String[][] { new String[] { META_CATEG_NAME, CATEG_LVL2_NAME, CATEG_LVL3_NAME }, new String[] { META_CATEG_NAME, CATEG_LVL2_NAME } }; cubeDesc.init(getTestConfig()); }