Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:zanata/zanata-platform into eflod…
…en/editor-user-roles/ZNTA-2380
- Loading branch information
Showing
28 changed files
with
427 additions
and
129 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
build-tools/src/main/resources/zanata-build-tools/versions-rules.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<ruleset comparisonMethod="maven" | ||
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 http://mojo.codehaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd"> | ||
<!-- Thanks to Michael Piefel and Philip Helger: https://stackoverflow.com/a/22174801/14379 --> | ||
<ignoreVersions> | ||
<ignoreVersion type="regex">.*[-_\.](alpha|Alpha|ALPHA|b|beta|Beta|BETA|cr|CR|rc|RC|M|EA)[-_\.]?[0-9]*</ignoreVersion> | ||
</ignoreVersions> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
server/services/src/test/java/org/zanata/action/ActivateActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright 2018, Red Hat, Inc. and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.action; | ||
|
||
import org.apache.deltaspike.core.api.scope.GroupedConversation; | ||
import org.jglue.cdiunit.InRequestScope; | ||
import org.jglue.cdiunit.InSessionScope; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Answers; | ||
import org.mockito.Mock; | ||
import org.zanata.dao.AccountActivationKeyDAO; | ||
import org.zanata.exception.ActivationLinkExpiredException; | ||
import org.zanata.exception.KeyNotFoundException; | ||
import org.zanata.model.HAccount; | ||
import org.zanata.model.HAccountActivationKey; | ||
import org.zanata.seam.security.IdentityManager; | ||
import org.zanata.test.CdiUnitRunner; | ||
import org.zanata.ui.faces.FacesMessages; | ||
import org.zanata.util.UrlUtil; | ||
|
||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Inject; | ||
import java.util.Date; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author djansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a> | ||
*/ | ||
@InSessionScope | ||
@InRequestScope | ||
@RunWith(CdiUnitRunner.class) | ||
public class ActivateActionTest { | ||
|
||
@Produces | ||
@Mock | ||
private GroupedConversation conversation; | ||
@Produces | ||
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
private AccountActivationKeyDAO accountActivationKeyDAO; | ||
@Produces | ||
@Mock | ||
private IdentityManager identityManager; | ||
@Produces | ||
@Mock | ||
private UrlUtil urlUtil; | ||
@Produces | ||
@Mock | ||
private FacesMessages facesMessages; | ||
@Inject | ||
private ActivateAction action; | ||
|
||
@Before | ||
public void before() { | ||
action = new ActivateAction(conversation, accountActivationKeyDAO, | ||
identityManager, urlUtil, facesMessages); | ||
} | ||
|
||
@Test | ||
public void nullKeyTest() { | ||
action.setActivationKey(null); | ||
try { | ||
action.validateActivationKey(); | ||
Assert.fail("Expected KeyNotFoundException"); | ||
} catch (KeyNotFoundException knfe) { | ||
assertThat(knfe.getMessage()).contains("null activation key"); | ||
} | ||
} | ||
|
||
@Test | ||
public void keyNoLongerExists() { | ||
action.setActivationKey("1234567890"); | ||
when(accountActivationKeyDAO.findById(action.getActivationKey(), false)) | ||
.thenReturn(null); | ||
try { | ||
action.validateActivationKey(); | ||
Assert.fail("Expected KeyNotFoundException"); | ||
} catch (KeyNotFoundException knfe) { | ||
assertThat(knfe.getMessage()).contains("activation key: 1234567890"); | ||
} | ||
} | ||
|
||
@Test | ||
public void expiredKeyTest() { | ||
HAccountActivationKey key = new HAccountActivationKey(); | ||
key.setCreationDate(new Date(0L)); | ||
action.setActivationKey("1234567890"); | ||
when(accountActivationKeyDAO.findById(action.getActivationKey(), false)) | ||
.thenReturn(key); | ||
try { | ||
action.validateActivationKey(); | ||
Assert.fail("Expected ActivationLinkExpiredException"); | ||
} catch (ActivationLinkExpiredException alee) { | ||
assertThat(alee.getMessage()) | ||
.contains("Activation link expired:1234567890"); | ||
} | ||
} | ||
|
||
@Test | ||
public void activateTest() { | ||
HAccountActivationKey key = new HAccountActivationKey(); | ||
key.setCreationDate(new Date()); | ||
HAccount hAccount = new HAccount(); | ||
hAccount.setUsername("Aloy"); | ||
action.setActivationKey("1234567890"); | ||
when(accountActivationKeyDAO.findById(action.getActivationKey(), false)) | ||
.thenReturn(key); | ||
action.validateActivationKey(); | ||
// TODO ZNTA-2365 action.activate(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
server/services/src/test/java/org/zanata/adapter/AdapterUtilsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2018, Red Hat, Inc. and individual contributors | ||
* as indicated by the @author tags. See the copyright.txt file in the | ||
* distribution for a full listing of individual contributors. | ||
* | ||
* This is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU Lesser General Public License as | ||
* published by the Free Software Foundation; either version 2.1 of | ||
* the License, or (at your option) any later version. | ||
* | ||
* This software is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this software; if not, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
*/ | ||
package org.zanata.adapter; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.zanata.exception.FileFormatAdapterException; | ||
|
||
import java.net.URI; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Damian Jansen <a href="mailto:djansen@redhat.com">djansen@redhat.com</a> | ||
*/ | ||
public class AdapterUtilsTest { | ||
|
||
@Test | ||
public void testNull() { | ||
try { | ||
AdapterUtils.readStream(URI.create("")); | ||
Assert.fail("Expected IllegalArgumentException"); | ||
} catch (IllegalArgumentException iae) { | ||
assertThat(iae.getMessage()).contains("absolute"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testMalformed() { | ||
try { | ||
AdapterUtils.readStream(URI | ||
.create("http://2aff:eaff:eaff:7aff:8aff:5aff:faff:eaff:8080/foo")); | ||
Assert.fail("Expected FileFormatAdapterException"); | ||
} catch (FileFormatAdapterException ffae) { | ||
assertThat(ffae.getMessage()).contains("malformed"); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAccess() { | ||
try { | ||
AdapterUtils.readStream(URI.create("http://tmp")); | ||
Assert.fail("Expected FileFormatAdapterException"); | ||
} catch (FileFormatAdapterException ffae) { | ||
assertThat(ffae.getMessage()).contains("stream"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.