src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
LdifRevertor { public static LdifEntry reverseMove( Dn newSuperiorDn, Dn modifiedDn ) throws LdapException { LdifEntry entry = new LdifEntry(); Dn currentParent; Rdn currentRdn; Dn newDn; if ( newSuperiorDn == null ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13466_NEW_SUPERIOR_DN_NULL ) ); } if ( modifie...
@Test public void testReverseModifyDNMove() throws LdapException { Dn dn = new Dn( "cn=john doe, dc=example, dc=com" ); Dn newSuperior = new Dn( "ou=system" ); Rdn rdn = new Rdn( "cn=john doe" ); LdifEntry reversed = LdifRevertor.reverseMove( newSuperior, dn ); assertNotNull( reversed ); assertEquals( "cn=john doe,ou=s...
LdifRevertor { public static List<LdifEntry> reverseRename( Entry entry, Rdn newRdn, boolean deleteOldRdn ) throws LdapInvalidDnException { return reverseMoveAndRename( entry, null, newRdn, deleteOldRdn ); } private LdifRevertor(); static LdifEntry reverseAdd( Dn dn ); static LdifEntry reverseDel( Dn dn, Entry deleted...
@Test public void test11ReverseRenameSimpleSimpleNotOverlappingKeepOldRdnDontExistInEntry() throws LdapException { Dn dn = new Dn( "cn=test,ou=system" ); Rdn oldRdn = new Rdn( "cn=test" ); Rdn newRdn = new Rdn( "cn=joe" ); Entry entry = new DefaultEntry( dn, "objectClass: top", "objectClass: person", "cn: test", "sn: t...
Unicode { public static char bytesToChar( byte[] bytes ) { return bytesToChar( bytes, 0 ); } private Unicode(); static int countBytesPerChar( byte[] bytes, int pos ); static char bytesToChar( byte[] bytes ); static char bytesToChar( byte[] bytes, int pos ); static int countNbBytesPerChar( char car ); static int countB...
@Test public void testOneByteChar() { char res = Unicode.bytesToChar( new byte[] { 0x30 } ); assertEquals( '0', res ); } @Test public void testOneByteChar00() { char res = Unicode.bytesToChar( new byte[] { 0x00 } ); assertEquals( 0x00, res ); } @Test public void testOneByteChar7F() { char res = Unicode.bytesToChar( new...
LdifUtils { public static boolean isLDIFSafe( String str ) { if ( Strings.isEmpty( str ) ) { return true; } char currentChar = str.charAt( 0 ); if ( ( currentChar > 127 ) || !LDIF_SAFE_STARTING_CHAR_ALPHABET[currentChar] ) { return false; } for ( int i = 1; i < str.length(); i++ ) { currentChar = str.charAt( i ); if ( ...
@Test public void testIsLdifNullString() { assertTrue( LdifUtils.isLDIFSafe( null ) ); } @Test public void testIsLdifEmptyString() { assertTrue( LdifUtils.isLDIFSafe( "" ) ); } @Test public void testIsLdifSafeStartingWithNUL() { char c = ( char ) 0; assertFalse( LdifUtils.isLDIFSafe( c + testString ) ); } @Test public ...
BitString { public boolean getBit( int pos ) { if ( pos > nbBits ) { throw new IndexOutOfBoundsException( I18n.err( I18n.ERR_00002_CANNOT_FIND_BIT, pos, nbBits ) ); } int posBytes = pos >>> 3; int bitNumber = 7 - pos % 8; byte mask = ( byte ) ( 1 << bitNumber ); int res = bytes[posBytes] & mask; return res != 0; } BitS...
@Test public void testSingleBitBitString() throws DecoderException { BitString bitString = new BitString( new byte[] { 0x07, ( byte ) 0x80 } ); assertEquals( true, bitString.getBit( 0 ) ); }
LdifUtils { public static String stripLineToNChars( String str, int nbChars ) { int strLength = str.length(); if ( strLength <= nbChars ) { return str; } if ( nbChars < 2 ) { throw new IllegalArgumentException( I18n.err( I18n.ERR_13474_LINE_LENGTH_TOO_SHORT ) ); } int charsPerLine = nbChars - 1; int remaining = ( strLe...
@Test public void testStripLineToNChars() { String line = "abc"; try { LdifUtils.stripLineToNChars( line, 1 ); fail(); } catch ( IllegalArgumentException iae ) { } String res = LdifUtils.stripLineToNChars( line, 2 ); assertEquals( "ab\n c", res ); assertEquals( "abc", LdifUtils.stripLineToNChars( line, 3 ) ); } @Test p...
LdifUtils { public static String convertToLdif( Attributes attrs ) throws LdapException { return convertAttributesToLdif( AttributeUtils.toEntry( attrs, null ), DEFAULT_LINE_LENGTH ); } private LdifUtils(); static boolean isLDIFSafe( String str ); static String convertToLdif( Attributes attrs ); static String convertT...
@Test public void testConvertToLdifEncoding() throws LdapException { Attributes attributes = new BasicAttributes( "cn", "Saarbr\u00FCcken" ); String ldif = LdifUtils.convertToLdif( attributes ); assertEquals( "cn:: U2FhcmJyw7xja2Vu\n", ldif ); } @Test public void testConvertToLdifAttrWithNullValues() throws LdapExcepti...
LdifUtils { public static Attributes createJndiAttributes( Object... avas ) throws LdapException { StringBuilder sb = new StringBuilder(); int pos = 0; boolean valueExpected = false; for ( Object ava : avas ) { if ( !valueExpected ) { if ( !( ava instanceof String ) ) { throw new LdapInvalidAttributeValueException( Res...
@Test public void testCreateAttributesVarargs() throws LdapException, LdapLdifException, NamingException { String mOid = "m-oid: 1.2.3.4"; String description = "description"; Attributes attrs = LdifUtils.createJndiAttributes( "objectClass: top", "objectClass: metaTop", "objectClass: metaSyntax", mOid, "m-description", ...
LdifReader implements Iterable<LdifEntry>, Closeable { public List<LdifEntry> parseLdif( String ldif ) throws LdapLdifException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_13407_STARTS_PARSING_LDIF ) ); } if ( Strings.isEmpty( ldif ) ) { return new ArrayList<>(); } try ( BufferedReader bufferReader = ...
@Test public void testChangeTypeDeleteBadEntry() throws Exception { String ldif = "version: 1\n" + "dn: dc=example,dc=com\n" + "changetype: delete\n" + "attr1: test"; try ( LdifReader reader = new LdifReader() ) { assertThrows( LdapLdifException.class, () -> { reader.parseLdif( ldif ); } ); } } @Test public void testLd...
Unicode { public static byte[] charToBytes( char car ) { if ( car <= 0x007F ) { byte[] bytes = new byte[1]; bytes[0] = ( byte ) car; return bytes; } else if ( car <= 0x07FF ) { byte[] bytes = new byte[2]; bytes[0] = ( byte ) ( 0x00C0 + ( ( car & 0x07C0 ) >> 6 ) ); bytes[1] = ( byte ) ( 0x0080 + ( car & 0x3F ) ); return...
@Test public void testcharToBytesOne() { assertEquals( "0x00 ", Strings.dumpBytes( Unicode.charToBytes( ( char ) 0x0000 ) ) ); assertEquals( "0x61 ", Strings.dumpBytes( Unicode.charToBytes( 'a' ) ) ); assertEquals( "0x7F ", Strings.dumpBytes( Unicode.charToBytes( ( char ) 0x007F ) ) ); } @Test public void testcharToByt...
LdapConnectionConfig { public void setTrustManagers( TrustManager... trustManagers ) { if ( ( trustManagers == null ) || ( trustManagers.length == 0 ) || ( trustManagers.length == 1 && trustManagers[0] == null ) ) { throw new IllegalArgumentException( "TrustManagers must not be null or empty" ); } this.trustManagers = ...
@Test public void testNullTrustManagers() { LdapConnectionConfig config = new LdapConnectionConfig(); Assertions.assertThrows(IllegalArgumentException.class, () -> { config.setTrustManagers((TrustManager)null); }); } @Test public void testNullTrustManagers2() { LdapConnectionConfig config = new LdapConnectionConfig(); ...
LdifAnonymizer { public LdifAnonymizer() { try { schemaManager = new DefaultSchemaManager(); } catch ( Exception e ) { println( "Missing a SchemaManager !" ); System.exit( -1 ); } init( null, null, null, null ); } LdifAnonymizer(); LdifAnonymizer( SchemaManager schemaManager ); void setOut( PrintStream out ); void set...
@Test public void testLdifAnonymizer() throws Exception { String ldif = "dn: cn=test,dc=example,dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: test\n" + "sn: Test\n" + "\n" + "dn: cn=emmanuel,dc=acme,dc=com\n" + "ObjectClass: top\n" + "objectClass: person\n" + "cn: emmanuel\n" + "sn: lecharnye\n"+ "\...
UnaryFilter extends AbstractFilter { public static UnaryFilter not() { return new UnaryFilter(); } private UnaryFilter(); static UnaryFilter not(); static UnaryFilter not( Filter filter ); @Override StringBuilder build( StringBuilder builder ); }
@Test public void testNot() { AttributeDescriptionFilter attributeFilter = AttributeDescriptionFilter.present( "objectClass" ); assertEquals( "(!" + attributeFilter.build().toString() + ")", UnaryFilter.not( attributeFilter ).build().toString() ); AttributeValueAssertionFilter attributeValueAssertionFilter = AttributeV...
SetOfFiltersFilter extends AbstractFilter { public static SetOfFiltersFilter and( Filter... filters ) { return new SetOfFiltersFilter( FilterOperator.AND ).addAll( filters ); } private SetOfFiltersFilter( FilterOperator operator ); SetOfFiltersFilter add( Filter filter ); SetOfFiltersFilter addAll( Filter... filters )...
@Test public void testAnd() { AttributeDescriptionFilter attributeFilter = AttributeDescriptionFilter.present( "objectClass" ); AttributeValueAssertionFilter attributeValueAssertionFilter = AttributeValueAssertionFilter.equal( "objectClass", "person" ); String expected = expected( FilterOperator.AND, attributeFilter, a...
SetOfFiltersFilter extends AbstractFilter { public static SetOfFiltersFilter or( Filter... filters ) { return new SetOfFiltersFilter( FilterOperator.OR ).addAll( filters ); } private SetOfFiltersFilter( FilterOperator operator ); SetOfFiltersFilter add( Filter filter ); SetOfFiltersFilter addAll( Filter... filters ); ...
@Test public void testOr() { AttributeDescriptionFilter attributeFilter = AttributeDescriptionFilter.present( "objectClass" ); AttributeValueAssertionFilter attributeValueAssertionFilter = AttributeValueAssertionFilter.equal( "objectClass", "person" ); String expected = expected( FilterOperator.OR, attributeFilter, att...
FilterBuilder { public static MatchingRuleAssertionFilterBuilder extensible( String value ) { return new MatchingRuleAssertionFilterBuilder( null, value ); } FilterBuilder( Filter filter ); static FilterBuilder and( FilterBuilder... filters ); static FilterBuilder approximatelyEqual( String attribute, String value ); s...
@Test public void testExtensible() { assertEquals( "(cn:caseExactMatch:=Fred Flintstone)", extensible( "cn", "Fred Flintstone" ) .setMatchingRule( "caseExactMatch" ).toString() ); }
FilterBuilder { FilterBuilder( Filter filter ) { this.filter = filter; } FilterBuilder( Filter filter ); static FilterBuilder and( FilterBuilder... filters ); static FilterBuilder approximatelyEqual( String attribute, String value ); static FilterBuilder equal( String attribute, String value ); static MatchingRuleAsser...
@Test public void testFilterBuilder() { assertEquals( "(cn=Babs Jensen)", equal( "cn", "Babs Jensen" ).toString() ); assertEquals( "(!(cn=Tim Howes))", not( equal( "cn", "Tim Howes" ) ).toString() ); assertEquals( "(&(objectClass=Person)(|(sn=Jensen)(cn=Babs J\\2A)))", and( equal( "objectClass", "Person" ), or( equal( ...
MatchingRuleAssertionFilter extends AbstractFilter { public static MatchingRuleAssertionFilter extensible( String value ) { return new MatchingRuleAssertionFilter( null, value, FilterOperator.EXTENSIBLE_EQUAL ); } MatchingRuleAssertionFilter( String attribute, String value, FilterOperator operator ); static Ma...
@Test public void testExtensible() { assertEquals( "(cn:caseExactMatch:=Fred Flintstone)", extensible( "cn", "Fred Flintstone" ) .setMatchingRule( "caseExactMatch" ).toString() ); assertEquals( "(cn:=Betty Rubble)", extensible( "cn", "Betty Rubble" ).toString() ); assertEquals( "(sn:dn:2.4.6.8.10:=Barney Rubble)", exte...
AttributeDescriptionFilter extends AbstractFilter { public static AttributeDescriptionFilter present( String attribute ) { return new AttributeDescriptionFilter( attribute ); } private AttributeDescriptionFilter( String attribute ); static AttributeDescriptionFilter present( String attribute ); @Override StringBuilder...
@Test public void testPresent() { assertEquals( "(objectClass=*)", AttributeDescriptionFilter.present( "objectClass" ).build().toString() ); assertEquals( "(uid=*)", AttributeDescriptionFilter.present( "uid" ).build().toString() ); assertEquals( "(userPassword=*)", AttributeDescriptionFilter.present( "userPassword" ).b...
JarLdifSchemaLoader extends AbstractSchemaLoader { public JarLdifSchemaLoader() throws IOException, LdapException { initializeSchemas(); } JarLdifSchemaLoader(); @Override List<Entry> loadComparators( Schema... schemas ); @Override List<Entry> loadSyntaxCheckers( Schema... schemas ); @Override List<Entry> loadNormalize...
@Test public void testJarLdifSchemaLoader() throws Exception { JarLdifSchemaLoader loader = new JarLdifSchemaLoader(); SchemaManager sm = new DefaultSchemaManager( loader ); sm.loadWithDeps( "system" ); assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) ); assertFalse( sm.getRegistries().getAttr...
SchemaToLdif { public static void transform( List<Schema> schemas ) throws ParserException { if ( ( schemas == null ) || schemas.isEmpty() ) { if ( LOG.isWarnEnabled() ) { LOG.warn( I18n.msg( I18n.MSG_15000_NO_SCHEMA_DEFINED ) ); } return; } int i = 1; for ( Schema schema : schemas ) { if ( schema.getName() == null ) {...
@Test public void testConvertOC() throws ParserException, IOException { String expected = HEADER + "dn: m-oid=1.3.6.1.4.1.18060.0.4.2.3.14, ou=objectclasses, cn=testOC, ou=schema\n" + "objectclass: metaObjectClass\n" + "objectclass: metaTop\n" + "objectclass: top\n" + "m-oid: 1.3.6.1.4.1.18060.0.4.2.3.14\n" + "m-name: ...
Hex { public static String decodeHexString( String str ) throws InvalidNameException { if ( str == null || str.length() == 0 ) { throw new InvalidNameException( I18n.err( I18n.ERR_17037_MUST_START_WITH_SHARP ) ); } char[] chars = str.toCharArray(); if ( chars[0] != '#' ) { throw new InvalidNameException( I18n.err( I18n...
@Test public void testDecodeHexString() throws Exception { try { assertEquals( "", Hex.decodeHexString( "" ) ); fail( "should not get here" ); } catch ( NamingException e ) { } assertEquals( "", Hex.decodeHexString( "#" ) ); assertEquals( "F", Hex.decodeHexString( "#46" ) ); try { assertEquals( "F", Hex.decodeHexString...
DnNode { public synchronized DnNode<N> add( Dn dn ) throws LdapException { return add( dn, null ); } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn );...
@Test public void testAddNullDNNoElem() throws LdapException { DnNode<Dn> tree = new DnNode<Dn>(); assertThrows( LdapUnwillingToPerformException.class, () -> { tree.add( null ); } ); } @Test public void testAdd2EqualDNsNoElem() throws LdapException { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn1 = new Dn( "dc=b,dc=a" ); D...
DnNode { public synchronized boolean hasChildren() { return ( children != null ) && children.size() != 0; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( D...
@Test public void testHasChildren() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn1 = new Dn( "dc=b,dc=a" ); tree.add( dn1 ); assertTrue( tree.hasChildren() ); Map<String, DnNode<Dn>> children = tree.getChildren(); assertNotNull( children ); DnNode<Dn> child = children.get( new Rdn( "dc=a" ).getNormName()...
Asn1Buffer2 { public void put( byte b ) { if ( pos == size ) { extend(); } currentBuffer.buffer[size - pos - 1] = b; pos++; } Asn1Buffer2(); int getPos(); void put( byte b ); void put( byte[] bytes ); byte[] getBytes(); int getSize(); void clear(); @Override String toString(); }
@Test @Disabled public void testBytesPerf() { long t0 = System.currentTimeMillis(); for ( int j = 0; j < 1000; j++ ) { Asn1Buffer buffer = new Asn1Buffer(); for ( int i = 0; i < 409600; i++ ) { buffer.put( new byte[] { 0x01, ( byte ) i } ); } } long t1 = System.currentTimeMillis(); System.out.println( "Delta: " + ( t1 ...
DnNode { public synchronized boolean isLeaf() { return !hasChildren(); } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean hasEle...
@Test public void testIsLeaf() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn ); assertFalse( tree.isLeaf() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertFalse( child.isLeaf() ); child = child.getChild( new Rdn( "dc=b" ) ); assertFalse( child.is...
DnNode { public synchronized N getElement() { return nodeElement; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean hasElement(...
@Test public void testGetElement() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); assertNull( tree.getElement() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertNull( child.getElement() ); child = child.getChild( new Rdn( "dc=b" ) ); assertN...
DnNode { public synchronized boolean hasElement() { return nodeElement != null; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boole...
@Test public void testHasElement() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); assertFalse( tree.hasElement() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertFalse( child.hasElement() ); child = child.getChild( new Rdn( "dc=b" ) ); asser...
DnNode { public synchronized int size() { int size = 1; if ( children.size() != 0 ) { for ( DnNode<N> node : children.values() ) { size += node.size(); } } return size; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int si...
@Test public void testSize() throws LdapException { DnNode<Dn> tree = new DnNode<Dn>(); assertEquals( 1, tree.size() ); tree.add( new Dn( "dc=b,dc=a" ) ); assertEquals( 3, tree.size() ); tree.add( new Dn( "dc=f,dc=a" ) ); assertEquals( 4, tree.size() ); tree.add( new Dn( "dc=a,dc=f,dc=a" ) ); assertEquals( 5, tree.size...
DnNode { public synchronized DnNode<N> getParent() { return parent; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean hasElemen...
@Test public void testGetParent() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); assertNull( tree.getParent() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertEquals( tree, child.getParent() ); DnNode<Dn> child1 = child.getChild( new Rdn( "d...
DnNode { public synchronized boolean hasParent() { return parent != null; } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement( Dn dn ); synchronized boolean has...
@Test public void testHasParent() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); assertFalse( tree.hasParent() ); DnNode<Dn> child = tree.getChild( new Rdn( "dc=a" ) ); assertTrue( child.hasParent() ); DnNode<Dn> child1 = child.getChild( new Rdn( "dc=b" ) ...
DnNode { public synchronized boolean contains( Rdn rdn ) { return children.containsKey( rdn.getNormName() ); } DnNode(); DnNode( N element ); DnNode( Dn dn, N element ); synchronized boolean isLeaf(); synchronized boolean isLeaf( Dn dn ); synchronized int size(); synchronized N getElement(); synchronized N getElement...
@Test public void testContains() throws Exception { DnNode<Dn> tree = new DnNode<Dn>(); Dn dn = new Dn( "dc=c,dc=b,dc=a" ); tree.add( dn, dn ); Rdn rdnA = new Rdn( "dc=a" ); Rdn rdnB = new Rdn( "dc=b" ); Rdn rdnC = new Rdn( "dc=c" ); assertTrue( tree.contains( rdnA ) ); assertFalse( tree.contains( rdnB ) ); assertFalse...
DnNode { public synchronized boolean hasParentElement( Dn dn ) { List<Rdn> rdns = dn.getRdns(); DnNode<N> currentNode = this; boolean hasElement = false; for ( int i = rdns.size() - 1; i >= 0; i-- ) { Rdn rdn = rdns.get( i ); if ( currentNode.hasChildren() ) { currentNode = currentNode.children.get( rdn.getNormName() )...
@Test public void testHasParentElement() throws Exception { DnNode<Dn> dnLookupTree = new DnNode<Dn>(); Dn dn1 = new Dn( "dc=directory,dc=apache,dc=org" ); Dn dn2 = new Dn( "dc=mina,dc=apache,dc=org" ); Dn dn3 = new Dn( "dc=test,dc=com" ); Dn dn4 = new Dn( "dc=acme,dc=com" ); Dn dn5 = new Dn( "dc=acme,c=us,dc=com" ); D...
DnNode { public synchronized void rename( Rdn newRdn ) throws LdapException { Dn temp = nodeDn.getParent(); temp = temp.add( newRdn ); Rdn oldRdn = nodeRdn; nodeRdn = temp.getRdn(); nodeDn = temp; if ( parent != null ) { parent.children.remove( oldRdn.getNormName() ); parent.children.put( nodeRdn.getNormName(), this );...
@Test public void testRename() throws Exception { DnNode<Dn> rootNode = new DnNode<Dn>(); Dn dn = new Dn( "dc=directory,dc=apache,dc=org" ); rootNode.add( dn ); Rdn childRdn = new Rdn( "dc=org" ); DnNode<Dn> child = rootNode.getChild( childRdn ); assertNotNull( child ); Rdn newChildRdn = new Rdn( "dc=neworg" ); child.r...
TriggerSpecificationParser { public synchronized TriggerSpecification parse( String spec ) throws ParseException { TriggerSpecification triggerSpecification; if ( Strings.isEmpty( spec ) ) { return null; } reset( spec ); try { triggerSpecification = this.parser.wrapperEntryPoint(); } catch ( TokenStreamException e ) { ...
@Test public void testWithOperationParameters() throws Exception { TriggerSpecification triggerSpecification = null; String spec = "AFTER Delete CALL \"BackupUtilities.backupDeletedEntry\" ($name, $deletedEntry);"; triggerSpecification = parser.parse( spec ); assertNotNull( triggerSpecification ); assertEquals( trigger...
MaxValueCountItem extends ProtectedItem { @Override public int hashCode() { int hash = 37; if ( items != null ) { for ( MaxValueCountElem item : items ) { if ( item != null ) { hash = hash * 17 + item.hashCode(); } else { hash = hash * 17 + 37; } } } return hash; } MaxValueCountItem( Set<MaxValueCountElem> items ); Ite...
@Test public void testHashCodeReflexive() throws Exception { assertEquals( maxValueCountItemA.hashCode(), maxValueCountItemA.hashCode() ); } @Test public void testHashCodeSymmetric() throws Exception { assertEquals( maxValueCountItemA.hashCode(), maxValueCountItemACopy.hashCode() ); assertEquals( maxValueCountItemACopy...
RemoteFlowApiClient implements CompleterClient { @Override public FlowId createFlow(String functionId) { try { APIModel.CreateGraphRequest createGraphRequest = new APIModel.CreateGraphRequest(functionId); ObjectMapper objectMapper = FlowRuntimeGlobals.getObjectMapper(); byte[] body = objectMapper.writeValueAsBytes(crea...
@Test public void createFlow() throws Exception { String functionId = "functionId"; HttpClient.HttpResponse response = responseWithCreateGraphResponse(testFlowId); when(mockHttpClient.execute(requestContainingFunctionId(functionId))).thenReturn(response); FlowId flowId = completerClient.createFlow(functionId); assertNo...
SpringCloudFunctionInvoker implements FunctionInvoker, Closeable { @Override public Optional<OutputEvent> tryInvoke(InvocationContext ctx, InputEvent evt) { SpringCloudMethod method = loader.getFunction(); Object[] userFunctionParams = coerceParameters(ctx, method, evt); Object result = tryInvoke(method, userFunctionPa...
@Test public void invokesFunctionWithFluxOfMultipleItems() { SpringCloudFunction fnWrapper = new SpringCloudFunction(x -> x, new SimpleFunctionInspector()); Object result = invoker.tryInvoke(fnWrapper, new Object[]{ Arrays.asList("hello", "world") }); assertThat(result).isInstanceOf(List.class); assertThat((List) resul...
RemoteFlowApiClient implements CompleterClient { @Override public CompletionId supply(FlowId flowId, Serializable supplier, CodeLocation codeLocation) { return addStageWithClosure(APIModel.CompletionOperation.SUPPLY, flowId, supplier, codeLocation, Collections.emptyList()); } RemoteFlowApiClient(String apiUrlBase, Blob...
@Test public void supply() throws Exception { String contentType = "application/java-serialized-object"; String testBlobId = "BLOBID"; BlobResponse blobResponse = makeBlobResponse(lambdaBytes, contentType, testBlobId); when(blobStoreClient.writeBlob(testFlowId, lambdaBytes, contentType)).thenReturn(blobResponse); HttpC...
RemoteFlowApiClient implements CompleterClient { @Override public CompletionId invokeFunction(FlowId flowId, String functionId, byte[] data, HttpMethod method, Headers headers, CodeLocation codeLocation) { APIModel.HTTPReq httpReq = new APIModel.HTTPReq(); if (headers != null) { if (data.length > 0) { BlobResponse blob...
@Test public void invokeFunctionNormally() throws Exception { String testFunctionId = "TESTFUNCTION"; String blobid = "BLOBID"; byte[] invokeBody = "INPUTDATA".getBytes(); String contentType = "text/plain"; BlobResponse blobResponse = makeBlobResponse(invokeBody, contentType, blobid); when(blobStoreClient.writeBlob(eq(...
RemoteFlowApiClient implements CompleterClient { @Override public Object waitForCompletion(FlowId flowId, CompletionId id, ClassLoader ignored, long timeout, TimeUnit unit) throws TimeoutException { long msTimeout = TimeUnit.MILLISECONDS.convert(timeout, unit); long start = System.currentTimeMillis(); do { long lastSta...
@Test public void waitForCompletionNormally() throws Exception { String testBlobId = "BLOBID"; String testContentType = "application/java-serialized-object"; APIModel.Blob blob = new APIModel.Blob(); blob.blobId = testBlobId; blob.contentType = testContentType; APIModel.CompletionResult completionResult = APIModel.Comp...
Headers implements Serializable { public static String canonicalKey(String key) { if (!headerName.matcher(key).matches()) { return key; } String parts[] = key.split("-", -1); for (int i = 0; i < parts.length; i++) { String p = parts[i]; if (p.length() > 0) { parts[i] = p.substring(0, 1).toUpperCase() + p.substring(1).t...
@Test public void shouldCanonicalizeHeaders(){ for (String[] v : new String[][] { {"",""}, {"a","A"}, {"fn-ID-","Fn-Id-"}, {"myHeader-VaLue","Myheader-Value"}, {" Not a Header "," Not a Header "}, {"-","-"}, {"--","--"}, {"a-","A-"}, {"-a","-A"} }){ assertThat(Headers.canonicalKey(v[0])).isEqualTo(v[1]); } }
InputHandler { Map<String, InterceptorInstance> resolveInputInterceptors(String algorithmClassName) { Map<String,InterceptorInstance> result = new HashMap<String, InterceptorInstance>(); Class<?> clazz; try { clazz = Class.forName(algorithmClassName, false, getClass().getClassLoader()); } catch (ClassNotFoundException ...
@Test public void testInputHandlerResolveInputInterceptors() throws ExceptionReport, XmlException, IOException { System.out.println("Testing testInputHandlerResolveInputInterceptors..."); InputHandler instance = new InputHandler.Builder(simpleBufferAlgorithmInputArray, "org.n52.wps.server.algorithm.SimpleBufferAlgorith...
ExecuteResponseBuilder { public String getMimeType() { return getMimeType(null); } ExecuteResponseBuilder(ExecuteRequest request); void update(); String getMimeType(); String getMimeType(OutputDefinitionType def); InputStream getAsStream(); void setStatus(StatusType status); }
@Test public void testGetMimeTypeComplexOutputResponseDoc() { try { String sampleFileName = "src/test/resources/DTCExecuteComplexOutputResponseDocMimeTiff.xml"; File sampleFile = new File(sampleFileName); FileInputStream is; is = new FileInputStream(sampleFile); Document doc; doc = fac.newDocumentBuilder().parse(is); i...
ExecutionContext { public List<OutputDefinitionType> getOutputs() { return this.outputDefinitionTypes; } ExecutionContext(); ExecutionContext(OutputDefinitionType output); ExecutionContext(List< ? extends OutputDefinitionType> outputs); String getTempDirectoryPath(); List<OutputDefinitionType> getOutputs(); }
@Test public void testConstructor() { ExecutionContext ec; ec = new ExecutionContext((OutputDefinitionType)null); assertNotNull(ec.getOutputs()); assertEquals(0, ec.getOutputs().size()); ec = new ExecutionContext(Arrays.asList(new OutputDefinitionType[0])); assertNotNull(ec.getOutputs()); assertEquals(0, ec.getOutputs(...
InputHandler { InputDescriptionType getInputReferenceDescriptionType(String inputId) { for (InputDescriptionType tempDesc : this.processDesc.getDataInputs().getInputArray()) { if (inputId.equals(tempDesc.getIdentifier().getStringValue())) { return tempDesc; } } return null; } private InputHandler(Builder builder); Map...
@Test public void testInputHandlerResolveInputDescriptionTypes() throws ExceptionReport, XmlException, IOException { System.out.println("Testing testInputHandlerResolveInputDescriptionTypes..."); InputHandler instance = new InputHandler.Builder(simpleBufferAlgorithmInputArray, "org.n52.wps.server.algorithm.SimpleBuffer...
InputHandler { protected String getComplexValueNodeString(Node complexValueNode) { String complexValue; try { if(complexValueNode.getChildNodes().getLength() > 1){ complexValue = complexValueNode.getChildNodes().item(1).getNodeValue(); if(complexValue == null){ return XMLUtil.nodeToString(complexValueNode.getChildNodes...
@Test public void testInputHandlerGetComplexValueNodeString() throws ExceptionReport, XmlException, IOException { System.out.println("Testing testInputHandlerGetComplexValueNodeString..."); InputHandler instance = new InputHandler.Builder(simpleBufferAlgorithmInputArray, "org.n52.wps.server.algorithm.SimpleBufferAlgori...
ExecuteRequest extends Request implements IObserver { public void updateStatusError(String errorMessage) { StatusType status = StatusType.Factory.newInstance(); net.opengis.ows.x11.ExceptionReportDocument.ExceptionReport excRep = status .addNewProcessFailed().addNewExceptionReport(); excRep.setVersion("1.0.0"); Excepti...
@Test public void testUpdateStatusError() throws ExceptionReport, XmlException, IOException, SAXException, ParserConfigurationException { FileInputStream fis = new FileInputStream(new File("src/test/resources/LRDTCCorruptInputResponseDocStatusTrue.xml")); Document doc = fac.newDocumentBuilder().parse(fis); ExecuteReque...
OutputDataItem extends ResponseData { public void updateResponseForLiteralData(ExecuteResponseDocument res, String dataTypeReference){ OutputDataType output = prepareOutput(res); String processValue = BasicXMLTypeFactory.getStringRepresentation(dataTypeReference, obj); LiteralDataType literalData = output.addNewData()....
@Test public void testUpdateResponseForLiteralData() { for (ILiteralData literalData : literalDataList) { try { testLiteralOutput(literalData); } catch (Exception e) { System.out.println("Test failed for " + literalData.getClass() + " " + e); } mockupResponseDocument.getExecuteResponse().getProcessOutputs() .removeOutp...
RawData extends ResponseData { public InputStream getAsStream() throws ExceptionReport { try { if(obj instanceof ILiteralData){ return new ByteArrayInputStream(String.valueOf(obj.getPayload()).getBytes(Charsets.UTF_8)); } if(obj instanceof IBBOXData){ IBBOXData bbox = (IBBOXData) obj; StringBuilder builder = new String...
@Test public void testBBoxRawDataOutputCRS(){ IData envelope = new BoundingBoxData( new double[] { 46, 102 }, new double[] { 47, 103 }, "EPSG:4326"); InputStream is; try { RawData bboxRawData = new RawData(envelope, "BBOXOutputData", null, null, null, identifier, processDescription); is = bboxRawData.getAsStream(); Xml...
MainViewModel extends AndroidViewModel { void init() { rmConnector.connect(getApplication()); rmConnector.setOnDataReceiveListener(event -> receiveColourMessage(event)); rmConnector.setOnPeerChangedListener(event -> liveDataPeerChangedEvent.postValue(event)); rmConnector.setOnConnectSuccessListener(meshId -> liveDataMy...
@Test public void init_isCalled() { spyViewModel.init(); verify(rightMeshConnector).setOnConnectSuccessListener(any()); verify(rightMeshConnector).setOnPeerChangedListener(any()); verify(rightMeshConnector).setOnDataReceiveListener(any()); verify(spyViewModel).init(); }
MainViewModel extends AndroidViewModel { void toRightMeshWalletActivty() { try { rmConnector.toRightMeshWalletActivty(); } catch (RightMeshException e) { Log.e(TAG, e.toString()); } } MainViewModel(@NonNull Application application); void setRightMeshConnector(RightMeshConnector rmConnector); }
@Test public void toRightMeshWalletActivty_isCalled() throws RightMeshException { spyViewModel.toRightMeshWalletActivty(); verify(rightMeshConnector).toRightMeshWalletActivty(); verify(spyViewModel).toRightMeshWalletActivty(); }
MainViewModel extends AndroidViewModel { void sendColorMsg(MeshId targetMeshId, Colour msgColor) { try { if (targetMeshId != null) { String payload = targetMeshId.toString() + ":" + msgColor.toString(); rmConnector.sendDataReliable(targetMeshId, payload); } } catch (RightMeshException.RightMeshServiceDisconnectedExcept...
@Test public void sendColorMsg_nullTargetMeshId() throws RightMeshException { MeshId targetId = null; Colour msgColor = Colour.RED; String payload = String.valueOf(targetId) + ":" + msgColor; spyViewModel.sendColorMsg(targetId, msgColor); verify(rightMeshConnector, never()).sendDataReliable(targetId, payload); verify(s...
MainViewModel extends AndroidViewModel { @Override protected void onCleared() { try { rmConnector.stop(); } catch (RightMeshException.RightMeshServiceDisconnectedException e) { Log.e(TAG, "Service disconnected before stopping AndroidMeshManager with message" + e.getMessage()); } } MainViewModel(@NonNull Application app...
@Test public void onCleared_isCalled() throws RightMeshException { spyViewModel.onCleared(); verify(rightMeshConnector).stop(); verify(spyViewModel).onCleared(); }
RightMeshConnector implements MeshStateListener { @Override public void meshStateChanged(MeshId meshId, int state) { if (state == SUCCESS) { try { androidMeshManager.bind(meshPort); if (connectSuccessListener != null) { connectSuccessListener.onConnectSuccess(meshId); } androidMeshManager.on(DATA_RECEIVED, event -> { i...
@Test public void meshStateChanged_successEvent() throws RightMeshException, ClassNotFoundException { spyRightMeshConnector.meshStateChanged(meshId, MeshStateListener.SUCCESS); verify(androidMeshManager).bind(MESH_PORT); verify(spyRightMeshConnector).meshStateChanged(meshId, MeshStateListener.SUCCESS); }
RightMeshConnector implements MeshStateListener { public void stop() throws RightMeshException.RightMeshServiceDisconnectedException { androidMeshManager.stop(); } RightMeshConnector(int meshPort); void connect(Context context); @Override void meshStateChanged(MeshId meshId, int state); void stop(); void setOnDataRecei...
@Test public void stop_isCalled() throws RightMeshException.RightMeshServiceDisconnectedException { spyRightMeshConnector.stop(); verify(androidMeshManager).stop(); verify(spyRightMeshConnector).stop(); }
RightMeshConnector implements MeshStateListener { public void toRightMeshWalletActivty() throws RightMeshException { this.androidMeshManager.showSettingsActivity(); } RightMeshConnector(int meshPort); void connect(Context context); @Override void meshStateChanged(MeshId meshId, int state); void stop(); void setOnDataRe...
@Test public void toRightMeshWalletActivty_isCalled() throws RightMeshException { spyRightMeshConnector.toRightMeshWalletActivty(); verify(androidMeshManager).showSettingsActivity(); verify(spyRightMeshConnector).toRightMeshWalletActivty(); }
RightMeshConnector implements MeshStateListener { public void sendDataReliable(MeshId targetMeshId, String payload) throws RightMeshException, RightMeshException.RightMeshServiceDisconnectedException { androidMeshManager.sendDataReliable(androidMeshManager.getNextHopPeer(targetMeshId), meshPort, payload.getBytes(Charse...
@Test public void sendDataReliable_isCalled() throws RightMeshException { String payload = "abc"; spyRightMeshConnector.sendDataReliable(meshId, payload); verify(spyRightMeshConnector).sendDataReliable(any(), eq(payload)); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = ex...
@Test public void test1() { String input = "(1+0*1)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); } @Test public void test2() { String input = "(!0)"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEqual...
ParseBooleanOriginal { public int process() { _input = _input.replaceAll(" ", ""); _input = _input.replaceAll("!1", "0"); _input = _input.replaceAll("!0", "1"); Matcher m = p.matcher(_input); if(m.find()) { _input = _input.substring(1,_input.length()-1); } Matcher m1 = p1.matcher(_input); Matcher m2 = p2.matcher(_input...
@Test public void test3() { String input = "0"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResults = tester.process(); assertEquals("Result",0, testResults ); } @Test public void test4() { String input = "0 * 1 * 1"; ParseBooleanOriginal tester = new ParseBooleanOriginal(input); int testResu...
SecretSantaFinder { public Map<String, String> pair() { List<Family> families = new ArrayList<Family>(); if(2*maxFamilyMembers > totalNames){ return null; } for(String key: familyMembers.keySet()) { families.add(familyMembers.get(key)) ; } Collections.sort(families); List<String> receiveList = new ArrayList<String>(tot...
@Test public void testTooManyInAFamily() { String names = "A Smith, B Smith, C Smith, D Andersen, E Andersen"; String[] nameList = names.split(","); SecretSantaFinder ssf = new SecretSantaFinder(nameList); assertEquals(ssf.pair(), null); } @Test public void testUnique() { String names = "A Smith, B Smith, C Smith, D An...
CyclicWordsKata { public List<List<String>> process() { List<List<String>> processed = new ArrayList<List<String>>(); Map<Integer,List<String>> buckets ; List<List<String>> returnArray ; buckets = separateInputBySize(_input); if(buckets == null) return processed; for(int size: buckets.keySet()) { List<String> elements ...
@Test public void testOneCyclicPair() { String[] input = {"abc","acb", "cab"}; CyclicWordsKata tester = new CyclicWordsKata(input); List<List<String>> results = tester.process(); assertEquals("Result", 2, results.size()); } @Test public void testNull() { String[] input = null; CyclicWordsKata tester = new CyclicWordsKa...
ParseRomanNumerals { public String parse() { String returnValue = ""; String prefix = ""; String suffix = ""; while(_input/1000 > 0 ) { int current = _input/1000; int toBeParsed = _input%1000; returnValue = prefix + parseUnder1000(toBeParsed) + suffix + returnValue; _input = current; prefix += "("; suffix += ")"; } ret...
@Test public void test1() { int input = 1879; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = tester.parse(); assertEquals("Result","MDCCCLXXIX", testResults ); } @Test public void test2() { int input = 1; ParseRomanNumerals tester = new ParseRomanNumerals(input); String testResults = te...
StateMachine { public String execute(String input) { String startState = entryState; for(int i = 0; i < input.length();i++){ char event = input.charAt(i) ; if(_symbols.indexOf(event) < 0) { return null; } String key = startState + "_" + event; if (endStates.containsKey(key)) { startState = endStates.get(key); } } if (s...
@Test public void test1 () { StateMachine fsm = new StateMachine("0,1", "EVEN:pass,ODD:fail,BAD:fail", "EVEN:ODD:1,ODD:EVEN:1,ODD:BAD:0"); assertEquals("pass", fsm.execute("00110")); assertEquals("fail", fsm.execute("00111")); assertEquals("fail", fsm.execute("001110000110011")); assertEquals("fail", null,fsm.execute("...
ShellMode { public static ShellMode from(String... arguments) { if (runInBatchMode(arguments)) { return new BatchMode(extractCommand(arguments)); } return new InteractiveMode(); } static String usage(); static ShellMode from(String... arguments); static ShellMode batch(String command); static ShellMode interactive(); ...
@Test(expected = IllegalArgumentException.class) public void illegalFlagsShouldBeDetected() { ShellMode mode = ShellMode.from("--interactive --foo"); }
Script extends ShellCommand implements Iterable<ShellCommand> { public Script(List<ShellCommand> commands) { this.commands = new ArrayList<ShellCommand>(commands); } Script(List<ShellCommand> commands); @Override void execute(ShellCommandHandler handler); Iterator<ShellCommand> iterator(); @Override int hashCode(); @Ov...
@Test public void toFileShouldCreateANonEmptyFile() throws FileNotFoundException { final ShellCommand script = script(history(), version(), exit()); final String destination = "test.txt"; script.toFile(destination); File file = new File(destination); assertThat("no file generated!", file.exists()); assertThat("empty fi...
AuthResource { public TempTokenResponse temporaryAuthToken(String scope) throws StorageException, UnsupportedEncodingException { if (Strings.isNullOrEmpty(scope)) { scope = "all"; } String tempToken = sessionManager.storeNewTempToken(); String xanauthURL = "xanauth: + URLEncoder.encode(scope, "UTF-8"); TempTokenRespons...
@Test public void temporaryAuthToken() throws Exception { SessionManager mockManager = mock(SessionManager.class); when(mockManager.storeNewTempToken()).thenReturn("dummyToken"); AuthResource resource = new AuthResource(mockManager, null, "localhost"); TempTokenResponse response = resource.temporaryAuthToken("doc"); as...
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningChildNodes(Node<T> x) { if (x == null || x.right == null) { return 0; } return x.right.weight + addWeightsOfRightLeaningChildNodes(x.right); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaning...
@Test public void addWeightsOfRightLeaningChildNodesNoChildren() throws Exception { Node<InvariantSpan> x = new Node<>(new InvariantSpan(1, 1, documentHash)); assertEquals(0, RopeUtils.addWeightsOfRightLeaningChildNodes(x)); } @Test public void addWeightsOfRightLeaningChildNodesNullNode() throws Exception { assertEqual...
RopeUtils { public static <T extends StreamElement> long addWeightsOfRightLeaningParentNodes(Node<T> child) { if (child == null) { throw new IllegalStateException("child node can't be null"); } if (child.parent == null) { return 0; } return (child.isRightNode() ? child.parent.weight : 0) + addWeightsOfRightLeaningParen...
@Test public void addWeightsOfRightLeaningParentNodesChainedRight() throws Exception { Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(1, 3, documentHash)); Node<InvariantSpan> right = new Node.Builder<InvariantSpan>(1).right(right2).build(); new Node.Builder<InvariantSpan>(1).right(right).build(); assertEqua...
RopeUtils { public static <T extends StreamElement> long characterCount(Node<T> x) { if (x == null) { return 0; } if (x.isLeaf()) { return x.value.getWidth(); } return x.weight + addWeightsOfRightLeaningChildNodes(x); } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static long addWeightsOfRightLeaningPare...
@Test public void characterCount() throws Exception { Node<InvariantSpan> right = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> right2 = new Node<>(new InvariantSpan(1, 20, documentHash)); right.right = right2; Node<InvariantSpan> x = new Node.Builder<InvariantSpan>(10).right(right).build(); a...
ApplyOverlayOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; ApplyOverlayOp other = (ApplyOverlayOp) obj; if (!linkTypes.equals(other.linkTypes)) return false; if (!variantSpan.equals(other.v...
@Test public void equalsTrue() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); assertTrue(op1.equals(op2)); assertTrue(op2.equals(op1)); } @Test public void equalsVarian...
RopeUtils { public static <T extends StreamElement> Node<T> concat(List<Node<T>> orphans) { Iterator<Node<T>> it = orphans.iterator(); Node<T> orphan = it.next(); while (it.hasNext()) { orphan = RopeUtils.concat(orphan, it.next()); } return orphan; } static long addWeightsOfRightLeaningChildNodes(Node<T> x); static lo...
@Test public void concatLeft() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 10, documentHash)); Node<InvariantSpan> parent = RopeUtils.concat(left, null); assertEquals(10, parent.weight); assertNotNull(left.parent); } @Test public void concatNullLeftNullRight() throws Exception { assert...
RopeUtils { public static <T extends StreamElement> Node<T> findSearchNode(Node<T> x, long weight, Node<T> root) { if (root == null) { throw new IllegalArgumentException("root is null"); } if (x == null) { return root; } if (x.weight > weight) { return x; } return findSearchNode(x.parent, weight, root); } static long ...
@Test public void findSearchNode() throws Exception { }
RopeUtils { public static <T extends StreamElement> NodeIndex<T> index(long characterPosition, Node<T> x, long disp) { if (x == null) { throw new IllegalArgumentException("node is null"); } if (characterPosition < 1) { throw new IndexOutOfBoundsException("characterPosition must be greater than 0"); } if (x.isLeaf()) { ...
@Test public void indexDisplacement() throws Exception { Node<InvariantSpan> left = new Node<>(new InvariantSpan(1, 1, documentHash)); Node<InvariantSpan> right = new Node<>(new InvariantSpan(2, 3, documentHash)); Node<InvariantSpan> root = new Node.Builder<InvariantSpan>(1).left(left).right(right).build(); NodeIndex<I...
DefaultOulipoMachine implements OulipoMachine { @Override public InvariantSpan append(String text) throws IOException, MalformedSpanException { return iStream.append(text); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateKey); static DefaultOulipoMachi...
@Test public void append() throws Exception { DefaultOulipoMachine som = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); InvariantSpan span = som.append("Hello"); assertEquals(span.getStart(), 1); assertEquals(span.getWidth(), 5); span = som.append("World"); assertEq...
DefaultOulipoMachine implements OulipoMachine { @Override public String getText(InvariantSpan invariantSpan) throws IOException { assertSpanNotNull(invariantSpan); return iStream.getText(invariantSpan); } DefaultOulipoMachine(StreamLoader stream, RemoteFileManager remoteFileManager, String documentHash, Key privateK...
@Test public void getText() throws Exception { DefaultOulipoMachine som = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); som.append("Hello"); som.append("World"); String result = som.getText(new InvariantSpan(5, 5, documentHash)); assertEquals("oWorl", result); }
DefaultOulipoMachine implements OulipoMachine { @Override public void moveVariant(long to, VariantSpan variantSpan) throws MalformedSpanException, IOException { assertGreaterThanZero(to); assertSpanNotNull(variantSpan); vStream.move(to, variantSpan); oStream.move(to, variantSpan); if (writeDocFile) { documentBuilder.mo...
@Test public void moveVariant() throws Exception { DefaultOulipoMachine machine = DefaultOulipoMachine.createWritableMachine(streamLoader, new MockRemoteFileManager(), documentHash); machine.insert(1, "My first document"); assertEquals("My first document", getText(machine)); machine.moveVariant(1, new VariantSpan(4, 6)...
ApplyOverlayOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + linkTypes.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } ApplyOverlayOp(DataInputStream dis); ApplyOverlayOp(VariantSpan variantSpan, Set<Integer>...
@Test public void hashTrue() throws Exception { ApplyOverlayOp op1 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); ApplyOverlayOp op2 = new ApplyOverlayOp(new VariantSpan(1, 100), Sets.newHashSet(1, 10)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
SwapVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.SWAP); dos.writeLong(v1.start); dos.writeLong(v1.width); dos.writeLong(v2.start); dos.writeLong(v2.width); } o...
@Test public void encodeDecode() throws Exception { SwapVariantOp op = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.SWAP, dis.readByte()); SwapVariantOp decoded = new SwapVariant...
SwapVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; SwapVariantOp other = (SwapVariantOp) obj; if (!v1.equals(other.v1)) return false; if (!v2.equals(other.v2)) return false; return t...
@Test public void equalsFalse() throws Exception { SwapVariantOp op1 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); SwapVariantOp op2 = new SwapVariantOp(new VariantSpan(100, 10), new VariantSpan(200, 1)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
SwapVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + v1.hashCode(); result = prime * result + v2.hashCode(); return result; } SwapVariantOp(DataInputStream dis); SwapVariantOp(VariantSpan v1, VariantSpan v2); @Override byte[] encode...
@Test public void hashFalse() throws Exception { SwapVariantOp op1 = new SwapVariantOp(new VariantSpan(100, 10), new VariantSpan(200, 1)); SwapVariantOp op2 = new SwapVariantOp(new VariantSpan(100, 1), new VariantSpan(200, 1)); assertFalse(op1.hashCode() == op2.hashCode()); ; } @Test public void hashTrue() throws Excep...
PutOverlayMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_OVERLAY_MEDIA); dos.writeLong(to); dos.writeInt(hash); dos.writeInt(linkTypes.size()); for (Integer i ...
@Test public void encodeDecode() throws Exception { PutOverlayMediaOp op = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_OVERLAY_MEDIA, dis.readByte()); PutOverlayMediaOp decoded = new PutOverlay...
PutOverlayMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutOverlayMediaOp other = (PutOverlayMediaOp) obj; if (hash != other.hash) return false; if (!linkTypes.equals(other.linkTypes)...
@Test public void equalsFalse() throws Exception { PutOverlayMediaOp op1 = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); PutOverlayMediaOp op2 = new PutOverlayMediaOp(2, 1, Sets.newSet(10, 5)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
PutOverlayMediaOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + hash; result = prime * result + ((linkTypes == null) ? 0 : linkTypes.hashCode()); result = prime * result + (int) (to ^ (to >>> 32)); return result; } PutOverlayMediaOp(DataInp...
@Test public void hashFalse() throws Exception { PutOverlayMediaOp op1 = new PutOverlayMediaOp(1, 1, Sets.newSet(10, 5)); PutOverlayMediaOp op2 = new PutOverlayMediaOp(2, 1, Sets.newSet(10, 5)); assertFalse(op1.hashCode() == op2.hashCode()); } @Test public void hashTrue() throws Exception { PutOverlayMediaOp op1 = new ...
StorageService { public <T> void delete(String id, Class<T> clazz) throws StorageException { if (Strings.isNullOrEmpty(id)) { throw new IllegalArgumentException("Id is null"); } if (clazz == null) { throw new IllegalArgumentException("Class is null"); } String key = id + "!" + clazz.getName(); Field[] fields = clazz.ge...
@Test public void delete() throws Exception { TestObject to1 = new TestObject("1", "456"); TestObject to2 = new TestObject("2", "abc"); TestObject to3 = new TestObject("3", "xyz"); service.save(to1); service.save(to2); service.save(to3); service.delete("1", TestObject.class); service.delete("3", TestObject.class); Coll...
DeleteVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.DELETE); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); return os.toByteA...
@Test public void encode() throws Exception { DeleteVariantOp op = new DeleteVariantOp(new VariantSpan(1, 100)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.DELETE, dis.read()); assertEquals(1, dis.readLong()); assertEquals(100, dis.readLong()); ...
DeleteVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; DeleteVariantOp other = (DeleteVariantOp) obj; if (!variantSpan.equals(other.variantSpan)) return false; return true; } DeleteVar...
@Test public void equalsVariantsFalse() throws Exception { DeleteVariantOp op1 = new DeleteVariantOp(new VariantSpan(1, 100)); DeleteVariantOp op2 = new DeleteVariantOp(new VariantSpan(2, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
DeleteVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + variantSpan.hashCode(); return result; } DeleteVariantOp(DataInputStream dis); DeleteVariantOp(VariantSpan variantSpan); @Override byte[] encode(); @Override boolean equals(Obje...
@Test public void hashFalse() throws Exception { DeleteVariantOp op1 = new DeleteVariantOp(new VariantSpan(1, 100)); DeleteVariantOp op2 = new DeleteVariantOp(new VariantSpan(2, 100)); assertFalse(op1.hashCode() == op2.hashCode()); ; } @Test public void hashTrue() throws Exception { DeleteVariantOp op1 = new DeleteVari...
CopyVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.COPY); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); re...
@Test public void encodeDecode() throws Exception { CopyVariantOp op = new CopyVariantOp(100, new VariantSpan(50, 75)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.COPY, dis.readByte()); CopyVariantOp decoded = new CopyVariantOp(dis); assertEqual...
CopyVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; CopyVariantOp other = (CopyVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return fal...
@Test public void equalsPositionsFalse() throws Exception { CopyVariantOp op1 = new CopyVariantOp(1, new VariantSpan(1, 100)); CopyVariantOp op2 = new CopyVariantOp(2, new VariantSpan(1, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); } @Test public void equalsVariantsFalse() throws Exception { CopyV...
CopyVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } CopyVariantOp(DataInputStream dis); CopyVariantOp(long to, VariantSpan variantSpan); @...
@Test public void hashTrue() throws Exception { CopyVariantOp op1 = new CopyVariantOp(1, new VariantSpan(1, 100)); CopyVariantOp op2 = new CopyVariantOp(1, new VariantSpan(1, 100)); assertEquals(op1.hashCode(), op2.hashCode()); ; }
MoveVariantOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.MOVE); dos.writeLong(to); dos.writeLong(variantSpan.start); dos.writeLong(variantSpan.width); } os.flush(); re...
@Test public void encodeDecode() throws Exception { MoveVariantOp op = new MoveVariantOp(100, new VariantSpan(50, 75)); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.MOVE, dis.readByte()); MoveVariantOp decoded = new MoveVariantOp(dis); assertEqual...
StorageService { public <T> Collection<T> getAll(Class<T> clazz) throws ClassNotFoundException, StorageException, IOException { List<T> c = new ArrayList<>(); Map<String, String> ids = new HashMap<>(); try (DBIterator it = db.iterator()) { it.seekToFirst(); String prevId = null; while (it.hasNext()) { String key = new ...
@Test public void getAll() throws Exception { TestObject to1 = new TestObject("1", "456"); TestObject to2 = new TestObject("2", "abc"); TestObject to3 = new TestObject("3", "xyz"); service.save(to1); service.save(to2); service.save(to3); Collection<TestObject> results = service.getAll(TestObject.class); assertEquals(3,...
MoveVariantOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; MoveVariantOp other = (MoveVariantOp) obj; if (to != other.to) return false; if (!variantSpan.equals(other.variantSpan)) return fal...
@Test public void equalsVariantsFalse() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(1, new VariantSpan(2, 100)); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
MoveVariantOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + variantSpan.hashCode(); return result; } MoveVariantOp(DataInputStream dis); MoveVariantOp(long to, VariantSpan variantSpan); @...
@Test public void hashFalse() throws Exception { MoveVariantOp op1 = new MoveVariantOp(1, new VariantSpan(1, 100)); MoveVariantOp op2 = new MoveVariantOp(1, new VariantSpan(2, 100)); assertFalse(op1.hashCode() == op2.hashCode()); ; } @Test public void hashFalse2() throws Exception { MoveVariantOp op1 = new MoveVariantO...
PutInvariantSpanOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_SPAN); dos.writeLong(to); dos.writeLong(invariantStart); dos.writeLong(width); dos.writeInt...
@Test public void encodeDecode() throws Exception { PutInvariantSpanOp op = new PutInvariantSpanOp(100, 50, 1, 0); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_INVARIANT_SPAN, dis.readByte()); PutInvariantSpanOp decoded = new PutInvariantSpanO...
PutInvariantSpanOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantSpanOp other = (PutInvariantSpanOp) obj; if (ripIndex != other.ripIndex) return false; if (invariantStart != other...
@Test public void equalsFalse() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpanOp(100, 50, 1, 0); PutInvariantSpanOp op2 = new PutInvariantSpanOp(101, 50, 1, 0); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }
PutInvariantSpanOp extends Op { @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); result = prime * result + ripIndex; result = prime * result + (int) (invariantStart ^ (invariantStart >>> 32)); result = prime * result + (int) (to ^ (to >>> 32)); result = prime * result + (int) (widt...
@Test public void hashFalse() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpanOp(100, 50, 1, 0); PutInvariantSpanOp op2 = new PutInvariantSpanOp(101, 50, 1, 0); assertFalse(op1.hashCode() == op2.hashCode()); ; } @Test public void hashTrue() throws Exception { PutInvariantSpanOp op1 = new PutInvariantSpa...
PutInvariantMediaOp extends Op { @Override public byte[] encode() throws IOException { ByteArrayOutputStream os = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(os)) { dos.writeByte(Op.PUT_INVARIANT_MEDIA); dos.writeLong(to); dos.writeInt(ripIndex); } os.flush(); return os.toByteArray(); ...
@Test public void encodeDecode() throws Exception { PutInvariantMediaOp op = new PutInvariantMediaOp(100, 1); byte[] data = op.encode(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); assertEquals(Op.PUT_INVARIANT_MEDIA, dis.readByte()); PutInvariantMediaOp decoded = new PutInvariantMediaOp(...
PutInvariantMediaOp extends Op { @Override public boolean equals(Object obj) { if (this == obj) return true; if (!super.equals(obj)) return false; if (getClass() != obj.getClass()) return false; PutInvariantMediaOp other = (PutInvariantMediaOp) obj; if (ripIndex != other.ripIndex) return false; if (to != other.to) retu...
@Test public void equalsFalse() throws Exception { PutInvariantMediaOp op1 = new PutInvariantMediaOp(1, 2); PutInvariantMediaOp op2 = new PutInvariantMediaOp(2, 2); assertFalse(op1.equals(op2)); assertFalse(op2.equals(op1)); }