Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 140 additions & 72 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,81 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
<!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c)
2013-2015 ForgeRock AS. All Rights Reserved The contents of this file are
subject to the terms of the Common Development and Distribution License (the
License). You may not use this file except in compliance with the License.
You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License
for the specific language governing permission and limitations under the
License. When distributing Covered Code, include this CDDL Header Notice
in each file and include the License file at legal/CDDLv1.0.txt. If applicable,
add the following below the CDDL Header, with the fields enclosed by brackets
[] replaced by your own identifying information: "Portions Copyrighted [year]
[name of copyright owner]" -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Copyright (c) 2013-2015 ForgeRock AS. All Rights Reserved
<groupId>org.forgerock.openam.examples</groupId>
<artifactId>openam-auth-sample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

The contents of this file are subject to the terms
of the Common Development and Distribution License
(the License). You may not use this file except in
compliance with the License.
<properties>
<openam.version>14.1.1</openam.version>
<powermock.version>1.7.3</powermock.version>
<jacoco.version>0.7.9</jacoco.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

You can obtain a copy of the License at legal/CDDLv1.0.txt.
See the License for the specific language governing
permission and limitations under the License.
<repositories>
<repository>
<id>forgerock-releases</id>
<url>http://maven.forgerock.org/repo/releases</url>
</repository>
<repository>
<id>forgerock-snapshots</id>
<url>http://maven.forgerock.org/repo/snapshots</url>
</repository>
</repositories>

When distributing Covered Code, include this CDDL
Header Notice in each file and include the License file at legal/CDDLv1.0.txt.
If applicable, add the following below the CDDL Header,
with the fields enclosed by brackets [] replaced by
your own identifying information:
"Portions Copyrighted [year] [name of copyright owner]"
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openam-core</artifactId>
<version>${openam.version}</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openam-shared</artifactId>
<version>${openam.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

<groupId>org.forgerock.openam.examples</groupId>
<artifactId>openam-auth-sample</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- Testing -->
<!-- Mocking -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.7.RELEASE</version>
<scope>test</scope>
</dependency>

<properties>
<openam.version>13.0.0-SNAPSHOT</openam.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Code Coverage -->
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco.version}</version>
<classifier>runtime</classifier>
</dependency>
</dependencies>

<repositories>
<repository>
<id>forgerock-releases</id>
<url>http://maven.forgerock.org/repo/releases</url>
</repository>
<repository>
<id>forgerock-snapshots</id>
<url>http://maven.forgerock.org/repo/snapshots</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openam-core</artifactId>
<version>${openam.version}</version>
</dependency>
<dependency>
<groupId>org.forgerock.openam</groupId>
<artifactId>openam-shared</artifactId>
<version>${openam.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<execution>
<id>default-instrument</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>default-restore-instrumented-classes</id>
<phase>test</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>target/jacoco.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>target/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
26 changes: 26 additions & 0 deletions src/test/java/org/forgerock/openam/examples/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.forgerock.openam.examples;

public class Constants {

public static final String UI_LOGIN_HEADER = "SampleAuth";
public static final String UI_USERNAME_PROMPT = "User Name:";
public static final String UI_PASSWORD_PROMPT = "Password:";
public static final String CORRECT_USERNAME = "demo";
public static final String CORRECT_PASSWORD = "changeit";
public static final String INCORRECT_PASSWORD = "incorrect";
public static final String ERROR_USERNAME1 = "test1";
public static final String ERROR_USERNAME2 = "test2";
public static final String PASSWORD_IS_WRONG_EXCEPTION = "password is wrong";
public static final String UNKOWN_USERNAME = "unknown";
public static final String INVALID_STATE_EXCEPTION = "invalid state";
public static final String NULL_AUTHPRINCIPAL = "illegal null input";
public static final Object UI_USERNAME_PROMPT_NULL = "#USERNAME#";
public static final Object UI_PASSWORD_PROMPT_NULL = "#PASSWORD#";
public static final Object UI_STATE3 = "#THE DUMMY WILL NEVER BE SHOWN#";
public static final Object UI_PASSWORD_PROMPT_STAGE3 = "Passsword Prompt";
public static final Object HEADER_LOGIN = new StringBuilder().append(UI_LOGIN_HEADER).append(" Login").toString();
public static final Object HEADER_ERROR1 = "Error 1 occurred during the authentication";
public static final Object HEADER_ERROR2 = "Error 2 occurred during the authentication";
public static final String INIT_HEADER_ATTRIBUTE = "specificAttribute";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.forgerock.openam.examples;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;

@RunWith(BlockJUnit4ClassRunner.class)
public class SampleAuthPrincipalTest {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void compare() {
// Setup exception handling to confirm it is being thrown
exception.expect(NullPointerException.class);
exception.expectMessage(Constants.NULL_AUTHPRINCIPAL);
SampleAuthPrincipal sampleAuthPrincipal = new SampleAuthPrincipal(null);
Assert.assertNull(sampleAuthPrincipal);
}

@Test
public void hascode() {
SampleAuthPrincipal sampleAuthPrincipal = new SampleAuthPrincipal(Constants.CORRECT_USERNAME);
Assert.assertNotNull(sampleAuthPrincipal);
Assert.assertEquals(Constants.CORRECT_USERNAME, sampleAuthPrincipal.getName());
Assert.assertEquals(3079651, sampleAuthPrincipal.hashCode());
}

@Test
public void equals() {
SampleAuthPrincipal sampleAuthPrincipal = new SampleAuthPrincipal(Constants.CORRECT_USERNAME);
SampleAuthPrincipal sampleAuthPrincipal2 = new SampleAuthPrincipal(Constants.ERROR_USERNAME1);
SampleAuthPrincipal sampleAuthPrincipal3 = new SampleAuthPrincipal(Constants.CORRECT_USERNAME);
Assert.assertNotNull(sampleAuthPrincipal);
Assert.assertFalse(sampleAuthPrincipal.equals(null));
Assert.assertFalse(sampleAuthPrincipal.equals(1234));
Assert.assertFalse(sampleAuthPrincipal.equals(sampleAuthPrincipal2));
Assert.assertTrue(sampleAuthPrincipal.equals(sampleAuthPrincipal));
Assert.assertTrue(sampleAuthPrincipal.equals(sampleAuthPrincipal3));
}

}
Loading