Skip to content

Commit

Permalink
fix(jans-orm): fixed npe in filter processor and covered with tests
Browse files Browse the repository at this point in the history
docs: no docs required
  • Loading branch information
yuriyz committed Jul 25, 2022
1 parent c996b51 commit ef46516
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 7 deletions.
17 changes: 17 additions & 0 deletions jans-orm/filter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,28 @@
<version>1.0.2-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-orm-util</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.jans.orm.search.filter;

import io.jans.orm.util.StringHelper;
import org.testng.annotations.Test;

import static org.testng.Assert.assertNotNull;

/**
* @author Yuriy Z
*/
public class FileProcessorTest {

@Test
public void simpleFilter_whenRun_shouldProduceFilter() {
final Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("uid"), StringHelper.toLowerCase("1"));
FilterProcessor filterProcessor = new FilterProcessor();
assertNotNull(filterProcessor.excludeFilter(filter, FilterProcessor.OBJECT_CLASS_EQUALITY_FILTER, FilterProcessor.OBJECT_CLASS_PRESENCE_FILTER));
}
}
11 changes: 11 additions & 0 deletions jans-orm/filter/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="ormFilter" parallel="false">

<test name="UnitTests" enabled="true">
<classes>
<class name="io.jans.orm.search.filter.FileProcessorTest"/>
</classes>
</test>

</suite>
13 changes: 13 additions & 0 deletions jans-orm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<argLine>@{argLine}</argLine>
<failIfNoTests>false</failIfNoTests>
<trimStackTrace>false</trimStackTrace>
<suiteXmlFiles>
<suiteXmlFile>target/test-classes/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
18 changes: 18 additions & 0 deletions jans-orm/util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
<version>1.0.2-SNAPSHOT</version>
</parent>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Logging -->
<dependency>
Expand All @@ -26,6 +38,12 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@

package io.jans.orm.util;

import org.apache.commons.text.StringEscapeUtils;

import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

import org.apache.commons.lang.NotImplementedException;
import org.apache.commons.text.StringEscapeUtils;

public final class StringHelper {

public static final byte[] EMPTY_BYTES = new byte[0];
Expand Down Expand Up @@ -349,10 +348,6 @@ public static boolean toBoolean(Boolean value, boolean defaultValue) {
}

public static boolean isEmptyString(Object string) {
if (string == null) {
return false;
}

return !(string instanceof String) || isEmpty((String) string);
}

Expand Down
28 changes: 28 additions & 0 deletions jans-orm/util/src/test/java/io/jans/orm/util/StringHelperTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.jans.orm.util;

import org.testng.annotations.Test;

import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertFalse;

/**
* @author Yuriy Z
*/
public class StringHelperTest {

@Test
public void isEmptyString_forNull_shouldReturnTrue() {
assertTrue(StringHelper.isEmptyString(null));
}

@Test
public void isEmptyString_forEmptyString_shouldReturnTrue() {
assertTrue(StringHelper.isEmptyString(""));
}

@Test
public void isEmptyString_forNonEmptyString_shouldReturnFalse() {
assertFalse(StringHelper.isEmptyString("df"));
}

}
11 changes: 11 additions & 0 deletions jans-orm/util/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="ormUtil" parallel="false">

<test name="UnitTests" enabled="true">
<classes>
<class name="io.jans.orm.util.StringHelperTest"/>
</classes>
</test>

</suite>

0 comments on commit ef46516

Please sign in to comment.