Skip to content

Commit

Permalink
issue SAML-Toolkits#52: removed PowerMock agents as they are not need…
Browse files Browse the repository at this point in the history
…ed and break badly in JDK8
  • Loading branch information
Luis Miranda committed Sep 1, 2016
1 parent 8876430 commit 2a309bd
Show file tree
Hide file tree
Showing 14 changed files with 7 additions and 108 deletions.
9 changes: 1 addition & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,4 @@ Select a Tomcat Server in order to deploy the server.

### Unit Tests

Known issues while testing:

* [ECLEmma coverage plugin incompatible with PowerMock](http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue)

* When using @PrepareForTest and PowerMockito the breakpoints not does [not stop when debugging](http://stackoverflow.com/questions/35140575/powermockito-junit-and-eclemma-debugging-dosent-work). The solution is define Rules.

* Java7+ enforces bytecode verification and with Powermock you can experience a [java.lang.VerifyError](http://www.notonlyanecmplace.com/java-7-enforces-bytecode-verification/).
At Java8 bytecode verification is mandatory and there is no option to disable it :(
The unit tests use PowerMock but do not run with the PowerMock javaagents enabled. This means you will not be able to mock out static methods, but other PowerMock features will work.
14 changes: 1 addition & 13 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-javaagent</artifactId>
<version>1.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule-agent</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>

<!-- for log -->
<dependency>
Expand Down Expand Up @@ -111,7 +99,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<argLine>-XX:-UseSplitVerifier ${jacoco.agent.argLine}</argLine>
<argLine>${jacoco.agent.argLine}</argLine>
</configuration>
</plugin>
</plugins>
Expand Down
33 changes: 0 additions & 33 deletions core/src/test/java/com/onelogin/saml2/test/AuthTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,50 +32,17 @@
import javax.servlet.http.HttpSession;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;

import com.onelogin.saml2.Auth;
import com.onelogin.saml2.authn.SamlResponse;
import com.onelogin.saml2.exception.SettingsException;
import com.onelogin.saml2.exception.XMLEntityException;
import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.settings.SettingsBuilder;
import com.onelogin.saml2.util.Constants;
import com.onelogin.saml2.util.Util;

/*
* Known issues while testing
*
* ECLEmma coverage plugin incompatible with PowerMock
* http://stackoverflow.com/questions/23363212/powermock-eclemma-coverage-issue
*
* import org.junit.runner.RunWith;
* import org.powermock.modules.junit4.PowerMockRunner;
* @RunWith(PowerMockRunner.class)
*
*/
@PrepareForTest({Auth.class})
public class AuthTest {

/*
* When using @PrepareForTest and PowerMockito the breakpoints when debugging
* does not work. Define Rules!
* (http://stackoverflow.com/questions/35140575/powermockito-junit-and-eclemma-debugging-dosent-work)
*
* https://github.com/jayway/powermock/wiki/PowerMockRule
*
* import org.junit.Rule;
* import org.powermock.modules.junit4.rule.PowerMockRule;
* @Rule
* public PowerMockRule rule = new PowerMockRule();
*
*/

//import org.powermock.modules.junit4.rule.PowerMockRule;
//@Rule
//public PowerMockRule rule = new PowerMockRule();

/**
* Tests the constructor of Auth
* Case: No parameters
Expand Down
2 changes: 0 additions & 2 deletions core/src/test/java/com/onelogin/saml2/test/MetadataTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.security.cert.CertificateEncodingException;
import java.util.Calendar;

import org.powermock.core.classloader.annotations.PrepareForTest;
import org.w3c.dom.Document;
import org.junit.Test;

Expand All @@ -25,7 +24,6 @@
/**
* Tests the com.onelogin.saml2.Metadata class
*/
@PrepareForTest({Metadata.class})
public class MetadataTest {
/**
* Tests the constructor method of Metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,22 @@
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.api.support.membermodification.MemberMatcher.method;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
//import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.modules.junit4.rule.PowerMockRule;

import com.onelogin.saml2.authn.AuthnRequest;
import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.settings.SettingsBuilder;
import com.onelogin.saml2.util.Util;

@PrepareForTest({AuthnRequest.class})
public class AuthnRequestTest {

@Rule
public PowerMockRule rule = new PowerMockRule();

/**
* Tests the getEncodedAuthnRequest method of AuthnRequest
*
Expand Down Expand Up @@ -278,4 +262,4 @@ public void testAuthNDestination() throws Exception {
assertThat(authnRequestStr, containsString("<samlp:AuthnRequest"));
assertThat(authnRequestStr, not(containsString("Destination=\"http://idp.example.com/simplesaml/saml2/idp/SSOService.php\"")));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import org.junit.Rule;
import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand All @@ -31,12 +29,8 @@
import com.onelogin.saml2.util.Util;
import com.onelogin.saml2.util.Constants;

@PrepareForTest({SamlResponse.class})
public class AuthnResponseTest {

@Rule
public PowerMockRule rule = new PowerMockRule();


/**
* Tests the constructor of SamlResponse
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,20 @@

import java.security.PrivateKey;

import org.powermock.api.mockito.PowerMockito;
import org.w3c.dom.Document;

import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;

import com.onelogin.saml2.exception.XMLEntityException;
import com.onelogin.saml2.logout.LogoutRequest;
import com.onelogin.saml2.settings.Saml2Settings;
import com.onelogin.saml2.settings.SettingsBuilder;
import com.onelogin.saml2.util.Util;

@PrepareForTest({LogoutRequest.class})
public class LogoutRequestTest {

@Rule
public PowerMockRule rule = new PowerMockRule();

/**
* Tests the constructor and the getEncodedLogoutRequest method of LogoutRequest
*
Expand Down Expand Up @@ -701,4 +695,4 @@ public void testGetError() throws URISyntaxException, IOException, XMLEntityExce
logoutRequest.isValid();
assertNull(logoutRequest.getError());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.xml.xpath.XPathExpressionException;

import org.junit.Rule;
import org.junit.Test;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;

import com.onelogin.saml2.exception.XMLEntityException;
import com.onelogin.saml2.logout.LogoutResponse;
Expand All @@ -30,12 +27,8 @@
import com.onelogin.saml2.util.Util;
import com.onelogin.saml2.util.Constants;

@PrepareForTest({LogoutResponse.class})
public class LogoutResponseTest {

@Rule
public PowerMockRule rule = new PowerMockRule();

/**
* Tests the constructor, the build and the getEncodedLogoutResponse method of LogoutResponse
*
Expand Down Expand Up @@ -501,4 +494,4 @@ public void testGetError() throws URISyntaxException, IOException, XMLEntityExce
logoutResponse.isValid();
assertNull(logoutResponse.getError());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.onelogin.saml2.test.model;

import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;

import static org.junit.Assert.assertEquals;

Expand All @@ -10,7 +9,6 @@
/**
* Tests the com.onelogin.saml2.model.Contact class
*/
@PrepareForTest({Contact.class})
public class ContactTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.net.URL;

import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -15,7 +14,6 @@
/**
* Tests the com.onelogin.saml2.model.Organization class
*/
@PrepareForTest({Organization.class})
public class OrganizationTest {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.onelogin.saml2.test.model;

import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -13,7 +12,6 @@
/**
* Tests the com.onelogin.saml2.model.SamlResponseStatus class
*/
@PrepareForTest({SamlResponseStatus.class})
public class SamlResponseStatusTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.List;

import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.w3c.dom.Document;

import com.onelogin.saml2.Metadata;
Expand All @@ -25,7 +24,6 @@
/**
* Tests the com.onelogin.saml2.settings.Saml2Settings class
*/
@PrepareForTest({Saml2Settings.class})
public class Saml2SettingsTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.List;

import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;

import com.onelogin.saml2.exception.SettingsException;
import com.onelogin.saml2.model.Contact;
Expand All @@ -27,7 +26,6 @@
/**
* Tests the com.onelogin.saml2.settings.SettingsBuilder class
*/
@PrepareForTest({SettingsBuilder.class})
public class SettingBuilderTest {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.xml.security.signature.XMLSignatureException;
import org.joda.time.DateTime;
import org.junit.Test;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
Expand All @@ -61,7 +60,6 @@
/**
* Tests the com.onelogin.saml2.util.Util class
*/
@PrepareForTest({Util.class})
public class UtilsTest {

/**
Expand Down

0 comments on commit 2a309bd

Please sign in to comment.