@Test public void testPropertyBuilder() throws DirectoryException { PropertyBuilder createPropertyBuilder = createPropertyBuilder("www.sample.com,:127.0.0.1"); assertThat( createPropertyBuilder.rebaseHostString("www.sample.com,:127.0.0.1"), is("www.sample.com:173.230.129.147,:127.0.0.1")); assertThat( createPropertyBuilder.rebaseHostString("www.sample.com:74.125.128.99"), is("www.sample.com:74.125.128.99")); assertThat(createPropertyBuilder.rebaseHostString("www.google.com").length(), greaterThan(40)); assertThat(createPropertyBuilder.rebaseHostString(":127.0.0.1"), is(":127.0.0.1")); }
void reset() { DimensionBuilder db = new DimensionBuilder(); measures = db.build("Measures", new String[] {"Measures"}, new int[] {3}); measures.setMeasure(true); TestDimension region = db.build( "Region", new String[] {"All Region", "Region", "City", "Customer"}, new int[] {1, 5, 8, 200}); TestDimension time = db.build("Time", new String[] {"Year", "Month"}, new int[] {5, 12}); time.setTime(true); TestDimension products = db.build( "Products", new String[] {"All Products", "Category", "Product"}, new int[] {1, 3, 10}); TestDimension advertising = db.build( "Advertising", new String[] {"All Advertising", "Media", "Target", "Type"}, new int[] {1, 4, 3, 3}); TestDimension material = db.build( "Material", new String[] {"All Materials", "Category", "Brand", "Quality"}, new int[] {1, 4, 3, 3}); dimensions = new TestDimension[6]; dimensions[0] = measures; dimensions[1] = region; dimensions[2] = time; dimensions[3] = products; dimensions[4] = advertising; dimensions[5] = material; PropertyBuilder pb = new PropertyBuilder(); pb.build(products); pb.build(region); axes = new TestAxis[2]; axes[0] = TestOlapModelUtils.createAxis(new TestDimension[] {measures}); axes[1] = TestOlapModelUtils.createAxis(new TestDimension[] {products, time}); TestMember m = ((TestHierarchy) advertising.getHierarchies()[0]).getRootMembers()[0]; m = (TestMember) m.getChildMember().get(0); setSlicer(m); }
@Test(dataProvider = FROM_SPEC) public void testBuildWithArgs( final String type, final String format, final Class<? extends Property> expectedClass) { EnumMap<PropertyId, Object> args = new EnumMap<PropertyId, Object>(PropertyId.class); args.put(PropertyId.DESCRIPTION, "Example description"); Property built = PropertyBuilder.build(type, format, args); Assert.assertNotNull(built); Assert.assertEquals(built.getClass(), expectedClass); }
private void buildAndAssertProperty( final String type, final String format, final Class<? extends Property> expectedClass) { Property built = PropertyBuilder.build(type, format, null); Assert.assertNotNull( built, "Could not build for type: " + type + ", format: " + format + ", expected class: " + expectedClass); Assert.assertEquals(built.getClass(), expectedClass); Assert.assertEquals(built.getType(), type); Assert.assertEquals(built.getFormat(), format); }
public List<PropertyDeclaration> buildDeclarations( final CSSName cssName, final List<PropertyValue> values, final CSSOrigin origin, final boolean important, final boolean inheritAllowed) { final List<PropertyDeclaration> result = new ArrayList<>(4); checkValueCount(cssName, 1, 4, values.size()); final PropertyBuilder builder = getPropertyBuilder(); final CSSName[] props = getProperties(); PropertyDeclaration decl1; PropertyDeclaration decl2; PropertyDeclaration decl3; PropertyDeclaration decl4; switch (values.size()) { case 1: decl1 = (PropertyDeclaration) builder.buildDeclarations(cssName, values, origin, important, true).get(0); result.add(copyOf(decl1, props[0])); result.add(copyOf(decl1, props[1])); result.add(copyOf(decl1, props[2])); result.add(copyOf(decl1, props[3])); break; case 2: decl1 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(0, 1), origin, important, false) .get(0); decl2 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(1, 2), origin, important, false) .get(0); result.add(copyOf(decl1, props[0])); result.add(copyOf(decl2, props[1])); result.add(copyOf(decl1, props[2])); result.add(copyOf(decl2, props[3])); break; case 3: decl1 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(0, 1), origin, important, false) .get(0); decl2 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(1, 2), origin, important, false) .get(0); decl3 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(2, 3), origin, important, false) .get(0); result.add(copyOf(decl1, props[0])); result.add(copyOf(decl2, props[1])); result.add(copyOf(decl3, props[2])); result.add(copyOf(decl2, props[3])); break; case 4: decl1 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(0, 1), origin, important, false) .get(0); decl2 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(1, 2), origin, important, false) .get(0); decl3 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(2, 3), origin, important, false) .get(0); decl4 = (PropertyDeclaration) builder .buildDeclarations(cssName, values.subList(3, 4), origin, important, false) .get(0); result.add(copyOf(decl1, props[0])); result.add(copyOf(decl2, props[1])); result.add(copyOf(decl3, props[2])); result.add(copyOf(decl4, props[3])); break; } return result; }
@Test public void testUnknownType() { Assert.assertNull(PropertyBuilder.build("unknownType", "custom", null)); }
public List<PropertyDeclaration> buildDeclarations( final CSSName cssName, final List<PropertyValue> values, final CSSOrigin origin, final boolean important, final boolean inheritAllowed) { List<PropertyDeclaration> result = checkInheritAll(ALL, values, origin, important, inheritAllowed); if (result != null) { return result; } PropertyDeclaration fontStyle = null; PropertyDeclaration fontVariant = null; PropertyDeclaration fontWeight = null; PropertyDeclaration fontSize = null; PropertyDeclaration lineHeight = null; PropertyDeclaration fontFamily = null; boolean keepGoing = false; final ListIterator<PropertyValue> i = values.listIterator(); while (i.hasNext()) { PropertyValue value = (PropertyValue) i.next(); final CSSPrimitiveUnit type = value.getPrimitiveTypeN(); if (type == CSSPrimitiveUnit.CSS_IDENT) { // The parser will have given us ident values as they appear // (case-wise) in the CSS text since we might be creating // a font-family list out of them. Here we want the normalized // (lowercase) version though. final String lowerCase = value.getStringValue().toLowerCase(); value = new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, lowerCase, lowerCase); final IdentValue ident = checkIdent(cssName, value); if (ident == IdentValue.NORMAL) { // skip to avoid double set false positives continue; } if (IdentSet.FONT_STYLES.contains(ident)) { if (fontStyle != null) { throw new CSSParseException(LangId.NO_TWICE, -1, "font-style"); } fontStyle = new PropertyDeclaration(CSSName.FONT_STYLE, value, important, origin); } else if (IdentSet.FONT_VARIANTS.contains(ident)) { if (fontVariant != null) { throw new CSSParseException(LangId.NO_TWICE, -1, "font-variant"); } fontVariant = new PropertyDeclaration(CSSName.FONT_VARIANT, value, important, origin); } else if (IdentSet.FONT_WEIGHTS.contains(ident)) { if (fontWeight != null) { throw new CSSParseException(LangId.NO_TWICE, -1, "font-weight"); } fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, value, important, origin); } else { keepGoing = true; break; } } else if (type == CSSPrimitiveUnit.CSS_NUMBER && value.getFloatValue() > 0) { if (fontWeight != null) { throw new CSSParseException(LangId.NO_TWICE, -1, "font-weight"); } final IdentValue weight = Conversions.getNumericFontWeight(value.getFloatValue()); if (weight == null) { throw new CSSParseException(LangId.INVALID_FONT_WEIGHT, -1, value.getCssText()); } final PropertyValue replacement = new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, weight.toString(), weight.toString()); replacement.setIdentValue(weight); fontWeight = new PropertyDeclaration(CSSName.FONT_WEIGHT, replacement, important, origin); } else { keepGoing = true; break; } } if (keepGoing) { i.previous(); PropertyValue value = (PropertyValue) i.next(); if (value.getPrimitiveTypeN() == CSSPrimitiveUnit.CSS_IDENT) { final String lowerCase = value.getStringValue().toLowerCase(); value = new PropertyValueImp(CSSPrimitiveUnit.CSS_IDENT, lowerCase, lowerCase); } final PropertyBuilder fontSizeBuilder = CSSName.getPropertyBuilder(CSSName.FONT_SIZE); List<PropertyDeclaration> l = fontSizeBuilder.buildDeclarations( CSSName.FONT_SIZE, Collections.singletonList(value), origin, important, true); fontSize = (PropertyDeclaration) l.get(0); if (i.hasNext()) { value = (PropertyValue) i.next(); if (value.getOperator() == Token.TK_VIRGULE) { final PropertyBuilder lineHeightBuilder = CSSName.getPropertyBuilder(CSSName.LINE_HEIGHT); l = lineHeightBuilder.buildDeclarations( CSSName.LINE_HEIGHT, Collections.singletonList(value), origin, important, true); lineHeight = (PropertyDeclaration) l.get(0); } else { i.previous(); } } if (i.hasNext()) { final List<PropertyValue> families = new ArrayList<PropertyValue>(); while (i.hasNext()) { families.add(i.next()); } final PropertyBuilder fontFamilyBuilder = CSSName.getPropertyBuilder(CSSName.FONT_FAMILY); l = fontFamilyBuilder.buildDeclarations( CSSName.FONT_FAMILY, families, origin, important, true); fontFamily = (PropertyDeclaration) l.get(0); } } if (fontStyle == null) { fontStyle = new PropertyDeclaration( CSSName.FONT_STYLE, new PropertyValueImp(IdentValue.NORMAL), important, origin); } if (fontVariant == null) { fontVariant = new PropertyDeclaration( CSSName.FONT_VARIANT, new PropertyValueImp(IdentValue.NORMAL), important, origin); } if (fontWeight == null) { fontWeight = new PropertyDeclaration( CSSName.FONT_WEIGHT, new PropertyValueImp(IdentValue.NORMAL), important, origin); } if (fontSize == null) { throw new CSSParseException(LangId.FONT_SIZE_REQUIRED, -1); } if (lineHeight == null) { lineHeight = new PropertyDeclaration( CSSName.LINE_HEIGHT, new PropertyValueImp(IdentValue.NORMAL), important, origin); } // XXX font-family should be reset too (although does this really make sense?) result = new ArrayList<PropertyDeclaration>(ALL.length); result.add(fontStyle); result.add(fontVariant); result.add(fontWeight); result.add(fontSize); result.add(lineHeight); if (fontFamily != null) { result.add(fontFamily); } return result; }