Skip to content

Commit c162fc9

Browse files
committed
Add test/integration-tests to build
Issue gh-610
1 parent 943231e commit c162fc9

File tree

6 files changed

+209
-21
lines changed

6 files changed

+209
-21
lines changed

dependencies/build.gradle

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ dependencies {
5959
api "org.apache.directory.server:apacheds-server-jndi:1.5.5"
6060
api "org.apache.directory.shared:shared-ldap:0.9.15"
6161
api "org.apache.httpcomponents:httpclient:4.5.13"
62-
api "org.aspectj:aspectjrt"
63-
api "org.aspectj:aspectjweaver"
62+
api "org.aspectj:aspectjrt:1.9.7"
63+
api "org.aspectj:aspectjweaver:1.9.7"
6464
api "org.assertj:assertj-core:3.21.0"
6565
api "org.bouncycastle:bcpkix-jdk15on:1.69"
6666
api "org.bouncycastle:bcprov-jdk15on:1.69"
@@ -89,6 +89,10 @@ dependencies {
8989
api "org.slf4j:jcl-over-slf4j:1.7.32"
9090
api "org.slf4j:log4j-over-slf4j:1.7.32"
9191
api "org.slf4j:slf4j-api:1.7.32"
92+
api "org.slf4j:slf4j-log4j12:1.7.32"
93+
api "org.springframework.security:spring-security-config:6.0.0-SNAPSHOT"
94+
api "org.springframework.security:spring-security-core:6.0.0-SNAPSHOT"
95+
api "org.springframework.security:spring-security-ldap:6.0.0-SNAPSHOT"
9296
api "org.springframework.ldap:spring-ldap-core:2.3.4.RELEASE"
9397
api "org.synchronoss.cloud:nio-multipart-parser:1.1.0"
9498
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ include 'test-support'
2929
include 'ldif/ldif-core'
3030
include 'odm'
3131
////include 'sandbox'
32-
//include 'test/integration-tests'
32+
include 'test/integration-tests'
3333
//include 'test/integration-tests-spring20'
3434
//include 'test/integration-tests-spring25'
3535
//include 'test/integration-tests-spring30'

test/integration-tests/build.gradle

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ sourceSets {
1616
}
1717

1818
dependencies {
19+
management platform(project(":spring-ldap-dependencies"))
1920
implementation project(":spring-ldap-test"),
2021
project(":spring-ldap-core-tiger")
2122

@@ -35,22 +36,32 @@ dependencies {
3536
exclude group: "org.springframework", module: "spring-aop"
3637
}
3738

38-
provided "commons-pool:commons-pool",
39-
"org.springframework:spring-jdbc",
40-
"org.springframework:spring-orm"
41-
42-
testImplementation "org.springframework:spring-test",
43-
"org.springframework:spring-aop",
44-
"org.springframework:spring-expression",
45-
"org.hibernate:hibernate-core",
46-
"aspectj:aspectjrt:1.5.4",
47-
"aspectj:aspectjweaver:1.5.4",
48-
"hsqldb:hsqldb:1.8.0.7",
49-
"junit:junit",
50-
"org.springframework.security:spring-security-config",
51-
"org.slf4j:slf4j-log4j12",
52-
"org.assertj:assertj-core"
53-
39+
provided "commons-pool:commons-pool"
40+
provided "org.springframework:spring-jdbc"
41+
provided "org.springframework:spring-orm"
42+
43+
optional "org.apache.directory.server:apacheds-core-entry"
44+
optional "org.apache.directory.server:apacheds-core"
45+
optional "org.apache.directory.server:apacheds-protocol-ldap"
46+
optional "org.apache.directory.server:apacheds-protocol-shared"
47+
optional "org.apache.directory.server:apacheds-server-jndi"
48+
optional "org.apache.directory.shared:shared-ldap"
49+
optional "com.unboundid:unboundid-ldapsdk"
50+
51+
testImplementation "org.springframework:spring-test"
52+
testImplementation "org.springframework:spring-aop"
53+
testImplementation "org.springframework:spring-expression"
54+
testImplementation "org.hibernate:hibernate-core-jakarta"
55+
testImplementation "org.aspectj:aspectjrt"
56+
testImplementation "org.aspectj:aspectjweaver"
57+
testImplementation "org.hsqldb:hsqldb"
58+
testImplementation "junit:junit"
59+
testImplementation "org.springframework.security:spring-security-config"
60+
testImplementation "org.slf4j:slf4j-log4j12"
61+
testImplementation "org.assertj:assertj-core"
62+
63+
testImplementation platform('org.junit:junit-bom')
64+
testImplementation "org.junit.vintage:junit-vintage-engine"
5465

5566
testImplementation("org.springframework.security:spring-security-ldap") {
5667
exclude group: "org.springframework.ldap", module: "spring-ldap-core"
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright 2002-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.apache.directory.server.core.avltree;
18+
19+
import java.io.ByteArrayInputStream;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.DataInputStream;
22+
import java.io.DataOutputStream;
23+
import java.io.IOException;
24+
import java.util.Comparator;
25+
26+
import org.apache.directory.shared.ldap.util.StringTools;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
29+
30+
/**
31+
* Class to serialize the Array data.
32+
*
33+
* @author <a href="mailto:[email protected]">Apache Directory Project</a>
34+
* @version $Rev$, $Date$
35+
*/
36+
@SuppressWarnings("unchecked")
37+
public class ArrayMarshaller<E> implements Marshaller<ArrayTree<E>> {
38+
39+
/** static logger */
40+
private static final Logger LOG = LoggerFactory.getLogger(ArrayMarshaller.class);
41+
42+
/** used for serialized form of an empty AvlTree */
43+
private static final byte[] EMPTY_TREE = new byte[1];
44+
45+
/** marshaller to be used for marshalling the keys */
46+
private Marshaller<E> keyMarshaller;
47+
48+
/** key Comparator for the AvlTree */
49+
private Comparator<E> comparator;
50+
51+
/**
52+
* Creates a new instance of AvlTreeMarshaller with a custom key Marshaller.
53+
* @param comparator Comparator to be used for key comparision
54+
* @param keyMarshaller marshaller for keys
55+
*/
56+
public ArrayMarshaller(Comparator<E> comparator, Marshaller<E> keyMarshaller) {
57+
this.comparator = comparator;
58+
this.keyMarshaller = keyMarshaller;
59+
}
60+
61+
/**
62+
* Creates a new instance of AvlTreeMarshaller with the default key Marshaller which
63+
* uses Java Serialization.
64+
* @param comparator Comparator to be used for key comparision
65+
*/
66+
public ArrayMarshaller(Comparator<E> comparator) {
67+
this.comparator = comparator;
68+
this.keyMarshaller = DefaultMarshaller.INSTANCE;
69+
}
70+
71+
/**
72+
* Marshals the given tree to bytes
73+
* @param tree the tree to be marshalled
74+
*/
75+
public byte[] serialize(ArrayTree<E> tree) {
76+
if ((tree == null) || (tree.size() == 0)) {
77+
return EMPTY_TREE;
78+
}
79+
80+
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
81+
DataOutputStream out = new DataOutputStream(byteStream);
82+
byte[] data = null;
83+
84+
try {
85+
out.writeByte(0); // represents the start of an Array byte stream
86+
out.writeInt(tree.size());
87+
88+
for (int position = 0; position < tree.size(); position++) {
89+
E value = tree.get(position);
90+
byte[] bytes = this.keyMarshaller.serialize(value);
91+
92+
// Write the key length
93+
out.writeInt(bytes.length);
94+
95+
// Write the key if its length is not null
96+
if (bytes.length != 0) {
97+
out.write(bytes);
98+
}
99+
}
100+
101+
out.flush();
102+
data = byteStream.toByteArray();
103+
104+
// Try to deserialize, just to see
105+
try {
106+
deserialize(data);
107+
}
108+
catch (NullPointerException npe) {
109+
System.out.println("Bad serialization, tree : [" + StringTools.dumpBytes(data) + "]");
110+
throw npe;
111+
}
112+
113+
out.close();
114+
}
115+
catch (IOException ex) {
116+
ex.printStackTrace();
117+
}
118+
119+
return data;
120+
}
121+
122+
/**
123+
* Creates an Array from given bytes of data.
124+
* @param data byte array to be converted into an array
125+
*/
126+
public ArrayTree<E> deserialize(byte[] data) throws IOException {
127+
try {
128+
if ((data == null) || (data.length == 0)) {
129+
throw new IOException("Null or empty data array is invalid.");
130+
}
131+
132+
if ((data.length == 1) && (data[0] == 0)) {
133+
E[] array = (E[]) new Object[] {};
134+
ArrayTree<E> tree = new ArrayTree<E>(this.comparator, array);
135+
return tree;
136+
}
137+
138+
ByteArrayInputStream bin = new ByteArrayInputStream(data);
139+
DataInputStream din = new DataInputStream(bin);
140+
141+
byte startByte = din.readByte();
142+
143+
if (startByte != 0) {
144+
throw new IOException("wrong array serialized data format");
145+
}
146+
147+
int size = din.readInt();
148+
E[] nodes = (E[]) new Object[size];
149+
150+
for (int i = 0; i < size; i++) {
151+
// Read the object's size
152+
int dataSize = din.readInt();
153+
154+
if (dataSize != 0) {
155+
byte[] bytes = new byte[dataSize];
156+
157+
din.read(bytes);
158+
E key = this.keyMarshaller.deserialize(bytes);
159+
nodes[i] = key;
160+
}
161+
}
162+
163+
ArrayTree<E> arrayTree = new ArrayTree<E>(this.comparator, nodes);
164+
165+
return arrayTree;
166+
}
167+
catch (NullPointerException npe) {
168+
System.out.println("Bad tree : [" + StringTools.dumpBytes(data) + "]");
169+
throw npe;
170+
}
171+
}
172+
173+
}

test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerIntegrationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void prepareTestedInstance() throws Exception {
6969
}
7070

7171
jdbcTemplate.execute("drop table PERSON if exists");
72-
jdbcTemplate.execute("create table PERSON(fullname VARCHAR, lastname VARCHAR, description VARCHAR)");
72+
jdbcTemplate.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
7373
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
7474
"Sweden, Company1, Some Person" });
7575
}

test/integration-tests/src/test/java/org/springframework/ldap/itest/manager/ContextSourceAndDataSourceTransactionManagerNamespaceITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void prepareTestedInstance() throws Exception {
7171
}
7272

7373
jdbcTemplate.execute("drop table PERSON if exists");
74-
jdbcTemplate.execute("create table PERSON(fullname VARCHAR, lastname VARCHAR, description VARCHAR)");
74+
jdbcTemplate.execute("create table PERSON(fullname VARCHAR(256), lastname VARCHAR(256), description VARCHAR(256))");
7575
jdbcTemplate.update("insert into PERSON values(?, ?, ?)", new Object[] { "Some Person", "Person",
7676
"Sweden, Company1, Some Person" });
7777
}

0 commit comments

Comments
 (0)