| | |
| | | import org.opends.server.api.MatchingRuleFactory; |
| | | import org.opends.server.api.MatchingRule; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.protocols.asn1.ASN1Element; |
| | | import org.opends.server.protocols.asn1.ASN1OctetString; |
| | | import org.opends.server.schema.BooleanEqualityMatchingRuleFactory; |
| | | import org.opends.server.schema.DistinguishedNameEqualityMatchingRuleFactory; |
| | | import org.opends.server.schema.IntegerEqualityMatchingRuleFactory; |
| | | import org.opends.server.types.AttributeType; |
| | | import org.opends.server.types.AttributeValue; |
| | | import org.opends.server.types.ByteString; |
| | | import org.opends.server.types.LDAPException; |
| | | import org.opends.server.types.*; |
| | | import org.opends.server.protocols.asn1.ASN1Writer; |
| | | import org.opends.server.protocols.asn1.ASN1; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createEqualityFilter((String) null, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createEqualityFilter(type, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | // excepted behavior |
| | | } |
| | | |
| | | mvf = MatchedValuesFilter.createEqualityFilter(type, new ASN1OctetString( |
| | | mvf = MatchedValuesFilter.createEqualityFilter(type, ByteString.valueOf( |
| | | value)); |
| | | assertNotNull(mvf); |
| | | assertEquals(mvf.getRawAttributeType(), type); |
| | | assertEquals(mvf.getRawAssertionValue(), new ASN1OctetString(value)); |
| | | assertEquals(mvf.getRawAssertionValue(), ByteString.valueOf(value)); |
| | | assertEquals(mvf.getMatchType(), MatchedValuesFilter.EQUALITY_MATCH_TYPE); |
| | | checkEncodeDecode(mvf); |
| | | |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createEqualityFilter((String) null, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | AttributeValue attVal = null; |
| | | if (attType != null) |
| | | { |
| | | attVal = new AttributeValue(attType, value); |
| | | attVal = AttributeValues.create(attType, value); |
| | | } |
| | | |
| | | // Check null, null |
| | |
| | | // input parameter |
| | | String rawAttTypeTest = type; |
| | | AttributeType attTypeTest = DirectoryServer.getAttributeType(type); |
| | | ASN1OctetString subInitialTest = new ASN1OctetString(subInitial); |
| | | ByteString subInitialTest = ByteString.valueOf(subInitial); |
| | | List<ByteString> subAnyTest = |
| | | new ArrayList<ByteString>(subAny.size()); |
| | | for (String s : subAny) |
| | | { |
| | | subAnyTest.add(new ASN1OctetString(s)); |
| | | subAnyTest.add(ByteString.valueOf(s)); |
| | | } |
| | | ByteString subFinalTest = new ASN1OctetString(subFinal); |
| | | ByteString subFinalTest = ByteString.valueOf(subFinal); |
| | | |
| | | // test parameter |
| | | AttributeType attTypeCurrent; |
| | |
| | | { |
| | | |
| | | mvf = MatchedValuesFilter.createGreaterOrEqualFilter((String) null, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createGreaterOrEqualFilter(type, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | if ((type != null) && (value != null)) |
| | | { |
| | | mvf = MatchedValuesFilter.createGreaterOrEqualFilter(type, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertNotNull(mvf); |
| | | assertEquals(mvf.getRawAttributeType(), type); |
| | | assertEquals(mvf.getRawAssertionValue(), new ASN1OctetString(value)); |
| | | assertEquals(mvf.getRawAssertionValue(), ByteString.valueOf(value)); |
| | | assertEquals(mvf.getMatchType(), |
| | | MatchedValuesFilter.GREATER_OR_EQUAL_TYPE); |
| | | } |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createGreaterOrEqualFilter((String) null, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | AttributeValue attVal = null; |
| | | if (attType != null) |
| | | { |
| | | attVal = new AttributeValue(attType, value); |
| | | attVal = AttributeValues.create(attType, value); |
| | | } |
| | | |
| | | // Check null, null |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createLessOrEqualFilter((String) null, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | } |
| | | catch (NullPointerException e) |
| | | { |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createLessOrEqualFilter(type, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | } |
| | | catch (NullPointerException e) |
| | | { |
| | |
| | | |
| | | // Check type, value |
| | | mvf = MatchedValuesFilter.createLessOrEqualFilter(type, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertNotNull(mvf); |
| | | assertEquals(mvf.getRawAttributeType(), type); |
| | | assertEquals(mvf.getRawAssertionValue(), new ASN1OctetString(value)); |
| | | assertEquals(mvf.getRawAssertionValue(), ByteString.valueOf(value)); |
| | | assertEquals(mvf.getMatchType(), MatchedValuesFilter.LESS_OR_EQUAL_TYPE); |
| | | |
| | | // Check null, value |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createLessOrEqualFilter((String) null, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | } |
| | | catch (NullPointerException e) |
| | | { |
| | |
| | | AttributeValue attVal = null ; |
| | | if (attType != null) |
| | | { |
| | | new AttributeValue(attType, value); |
| | | AttributeValues.create(attType, value); |
| | | } |
| | | |
| | | // Check null, null |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createApproximateFilter((String) null, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createApproximateFilter(type, |
| | | (ASN1OctetString) null); |
| | | (ByteString) null); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | |
| | | // Check type, value |
| | | mvf = MatchedValuesFilter.createApproximateFilter(type, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertNotNull(mvf); |
| | | assertEquals(mvf.getRawAttributeType(), type); |
| | | assertEquals(mvf.getRawAssertionValue(), new ASN1OctetString(value)); |
| | | assertEquals(mvf.getRawAssertionValue(), ByteString.valueOf(value)); |
| | | assertEquals(mvf.getMatchType(), MatchedValuesFilter.APPROXIMATE_MATCH_TYPE); |
| | | |
| | | // Check null, value |
| | | try |
| | | { |
| | | mvf = MatchedValuesFilter.createApproximateFilter((String) null, |
| | | new ASN1OctetString(value)); |
| | | ByteString.valueOf(value)); |
| | | assertTrue(false, "Expected NullPointerException"); |
| | | } |
| | | catch (NullPointerException e) |
| | |
| | | AttributeValue attVal = null ; |
| | | if (attType != null) |
| | | { |
| | | attVal = new AttributeValue(attType, value); |
| | | attVal = AttributeValues.create(attType, value); |
| | | } |
| | | |
| | | // Check null, null |
| | |
| | | String rawAttTypeTest = type ; |
| | | AttributeType attTypeTest = DirectoryServer.getAttributeType(type) ; |
| | | String matchingRuleIdTest = matchingRule.getOID() ; |
| | | ASN1OctetString rawAttValueTest = (attTypeTest == null) ? null : new ASN1OctetString(value); |
| | | AttributeValue attValueTest = (attTypeTest == null) ? null : new AttributeValue(attTypeTest, value); |
| | | ByteString rawAttValueTest = (attTypeTest == null) ? null : ByteString.valueOf(value); |
| | | AttributeValue attValueTest = (attTypeTest == null) ? null : AttributeValues.create(attTypeTest, value); |
| | | // |
| | | // parameter used for the test. |
| | | String rawAttTypeTestCurrent; |
| | | AttributeType attTypeTestCurrent ; |
| | | String rawMatchingRuleidTestCurrent ; |
| | | MatchingRule matchingRuleidTestCurrent ; |
| | | ASN1OctetString rawAttValueTestCurrent; |
| | | ByteString rawAttValueTestCurrent; |
| | | AttributeValue attValueTestCurrent; |
| | | |
| | | |
| | |
| | | */ |
| | | private void checkEncodeDecode(MatchedValuesFilter mvf) |
| | | { |
| | | ASN1Element asn1Elt = mvf.encode() ; |
| | | ByteStringBuilder bsb = new ByteStringBuilder(); |
| | | ASN1Writer writer = ASN1.getWriter(bsb); |
| | | try |
| | | { |
| | | MatchedValuesFilter newMvf = MatchedValuesFilter.decode(asn1Elt) ; |
| | | mvf.encode(writer); |
| | | MatchedValuesFilter newMvf = MatchedValuesFilter.decode(ASN1 |
| | | .getReader(bsb)); |
| | | assertEquals(newMvf.toString(), mvf.toString()); |
| | | } |
| | | catch (LDAPException e) |
| | | catch (Exception e) |
| | | { |
| | | assertTrue(false, "Unexpected LDAPException ; msg=" + e.getMessage()); |
| | | } |