Skip to content

Commit

Permalink
Merge pull request #490 from zanata/fix-ft
Browse files Browse the repository at this point in the history
fix: functional test
  • Loading branch information
seanf committed Aug 29, 2017
2 parents c7100cc + 761474f commit e3b3edd
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import org.junit.Rule;
import org.junit.Test;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.SampleDataRule;

/**
* This is a class for experiment some things i.e. populate cargo instance with
Expand All @@ -31,7 +31,7 @@
*/
public class ExperimentTest {
@Rule
public SampleProjectRule sampleProjectRule = new SampleProjectRule();
public SampleDataRule sampleDataRule = new SampleDataRule();

@Test
public void test() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.zanata.rest.dto.resource.TextFlowTarget;
import org.zanata.rest.dto.resource.TranslationsResource;
import org.zanata.util.SampleDataResourceClient;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.SampleDataRule;
import org.zanata.util.ZanataRestCaller;
import java.util.List;
import static org.zanata.util.ZanataRestCaller.*;
Expand All @@ -31,7 +31,7 @@ public class CopyTransTuningTest {

private static final String PROJECT_SLUG = "ovirt-reports-history";
@Rule
public SampleProjectRule rule = new SampleProjectRule();
public SampleDataRule rule = new SampleDataRule();
private ZanataRestCaller restCaller;
private List<LocaleId> translatedLocales =
ImmutableList.<LocaleId> builder().add(new LocaleId("ja"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.zanata.page.administration.ServerConfigurationPage;
import org.zanata.util.Constants;
import org.zanata.util.PropertiesHolder;
import org.zanata.util.SampleDataRule;
import org.zanata.util.ZanataRestCaller;
import org.zanata.workflow.LoginWorkFlow;
import javax.ws.rs.client.Entity;
Expand Down Expand Up @@ -70,9 +71,9 @@ public void canConfigureRateLimitByWebUI() {
new LoginWorkFlow().signIn("admin", "admin")
.goToAdministration().goToServerConfigPage();
assertThat(serverConfigPage.getMaxConcurrentRequestsPerApiKey())
.isEqualTo("default is 6");
.isEqualTo(String.valueOf(SampleDataRule.CONCURRENT_RATE_LIMIT));
assertThat(serverConfigPage.getMaxActiveRequestsPerApiKey())
.isEqualTo("default is 2");
.isEqualTo(String.valueOf(SampleDataRule.ACTIVE_RATE_LIMIT));
AdministrationPage administrationPage =
serverConfigPage.inputMaxConcurrent(5).inputMaxActive(3).save();
// RHBZ1160651
Expand All @@ -87,10 +88,10 @@ public void canConfigureRateLimitByWebUI() {

@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void canCallServerConfigurationRestService() throws Exception {
Invocation.Builder clientRequest = clientRequestAsAdmin(
"rest/configurations/" + maxConcurrentPathParam);
Invocation.Builder clientRequest = clientRequestAsAdminWithQueryParam(
"rest/configurations/" + maxConcurrentPathParam, "configValue", 1);
// can put
clientRequest.put(Entity.json("1"));
clientRequest.put(null);
// can get single configuration
String rateLimitConfig = clientRequestAsAdmin(
"rest/configurations/" + maxConcurrentPathParam)
Expand All @@ -116,6 +117,19 @@ private static Invocation.Builder clientRequestAsAdmin(String path) {
.header("Content-Type", "application/xml");
}

private static Invocation.Builder clientRequestAsAdminWithQueryParam(String path, String paramName, Object paramValue) {
return new ResteasyClientBuilder().build()
.target(PropertiesHolder
.getProperty(Constants.zanataInstance.value()) + path)
.queryParam(paramName, paramValue)
.request(MediaType.APPLICATION_XML_TYPE)
.header("X-Auth-User", "admin")
.header("X-Auth-Token",
PropertiesHolder
.getProperty(Constants.zanataApiKey.value()))
.header("Content-Type", "application/xml");
}

@Test(timeout = ZanataTestCase.MAX_SHORT_TEST_DURATION)
public void serverConfigurationRestServiceOnlyAvailableToAdmin()
throws Exception {
Expand Down Expand Up @@ -160,9 +174,8 @@ public void canLimitConcurrentRestRequestsPerAPIKey() throws Exception {
final String iterationSlug = "version";
new ZanataRestCaller(TRANSLATOR, TRANSLATOR_API)
.createProjectAndVersion(projectSlug, iterationSlug, "gettext");
Invocation.Builder clientRequest = clientRequestAsAdmin(
"rest/configurations/" + maxConcurrentPathParam);
clientRequest.put(Entity.json("2"));
Invocation.Builder clientRequest = clientRequestAsAdminWithQueryParam(
"rest/configurations/" + maxConcurrentPathParam, "configValue", 2);
// prepare to fire multiple REST requests
final AtomicInteger atomicInteger = new AtomicInteger(1);
// requests from translator user
Expand Down Expand Up @@ -205,9 +218,9 @@ ImmutableList.<Callable<Integer>> builder()
@Test(timeout = 5000)
public void exceptionWillReleaseSemaphore() throws Exception {
// Given: max active is set to 1
Invocation.Builder configRequest = clientRequestAsAdmin(
"rest/configurations/" + maxActivePathParam);
configRequest.put(Entity.json("1")).close();
Invocation.Builder configRequest = clientRequestAsAdminWithQueryParam(
"rest/configurations/" + maxActivePathParam, "configValue", 1);
configRequest.put(null).close();
// When: multiple requests that will result in a mapped exception
Invocation.Builder clientRequest = clientRequestAsAdmin(
"rest/test/data/sample/dummy?exception=org.zanata.rest.NoSuchEntityException");
Expand All @@ -223,9 +236,9 @@ public void exceptionWillReleaseSemaphore() throws Exception {
@Test(timeout = 5000)
public void unmappedExceptionWillAlsoReleaseSemaphore() throws Exception {
// Given: max active is set to 1
Invocation.Builder configRequest = clientRequestAsAdmin(
"rest/configurations/" + maxActivePathParam);
configRequest.put(Entity.json("1")).close();
Invocation.Builder configRequest = clientRequestAsAdminWithQueryParam(
"rest/configurations/" + maxActivePathParam, "configValue", 1);
configRequest.put(null).close();
// When: multiple requests that will result in an unmapped exception
Invocation.Builder clientRequest = clientRequestAsAdmin(
"rest/test/data/sample/dummy?exception=java.lang.RuntimeException");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.zanata.page.WebDriverFactory;
import org.zanata.util.AllowAnonymousAccessRule;
import org.zanata.util.EnsureLogoutRule;
import org.zanata.util.SampleProjectRule;
import org.zanata.util.SampleDataRule;
import org.zanata.util.ZanataRestCaller;
import java.util.Set;

Expand Down Expand Up @@ -84,7 +84,7 @@ protected void after() {
@Rule
public RuleChain theOneRule = RuleChain
.outerRule(new AllowAnonymousAccessRule())
.around(new EnsureLogoutRule()).around(new SampleProjectRule());
.around(new EnsureLogoutRule()).around(new SampleDataRule());
/*
* rhbz1096552 - disable test timeout for now see
* https://bugzilla.redhat.com/show_bug.cgi?id=1096552
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.assertj.core.api.Assertions;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.zanata.model.HApplicationConfiguration;

/**
* @author Patrick Huang <a
Expand Down Expand Up @@ -93,6 +96,38 @@ public static void makeSampleProject() throws Exception {
createRequest("/project").put(EMPTY_ENTITY).close();
}

public static void setRateLimit(int active, int concurrent)
throws Exception {
String restUrl = PropertiesHolder.getProperty(Constants.zanataInstance
.value()) + "rest/configurations/c/";

Response response = new ResteasyClientBuilder().build()
.target(restUrl +
HApplicationConfiguration.KEY_MAX_ACTIVE_REQ_PER_API_KEY)
.queryParam("configValue", active)
.request(MediaType.APPLICATION_XML_TYPE)
.header("X-Auth-Token",
PropertiesHolder.getProperty(Constants.zanataApiKey
.value()))
.header("X-Auth-User", "admin")
.put(null);
Assertions.assertThat(response.getStatus()).isLessThan(300);
response.close();

response = new ResteasyClientBuilder().build()
.target(restUrl +
HApplicationConfiguration.KEY_MAX_CONCURRENT_REQ_PER_API_KEY)
.queryParam("configValue", concurrent)
.request(MediaType.APPLICATION_XML_TYPE)
.header("X-Auth-Token",
PropertiesHolder.getProperty(Constants.zanataApiKey
.value()))
.header("X-Auth-User", "admin")
.put(null);
Assertions.assertThat(response.getStatus()).isLessThan(300);
response.close();
}

public static void makeSampleLanguages() throws Exception {
createRequest("/languages").put(EMPTY_ENTITY).close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
* @author Patrick Huang
* <a href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class SampleProjectRule extends ExternalResource {
public class SampleDataRule extends ExternalResource {
public static final int CONCURRENT_RATE_LIMIT = 20;
public static final int ACTIVE_RATE_LIMIT = 10;

@Override
public void before() throws Throwable {
deleteExceptEssentialData();
Expand All @@ -40,5 +43,6 @@ public void before() throws Throwable {
userJoinsLanguageTeam("translator", locales);
userJoinsLanguageTeam("glossarist", locales);
makeSampleProject();
setRateLimit(ACTIVE_RATE_LIMIT, CONCURRENT_RATE_LIMIT);
}
}
5 changes: 3 additions & 2 deletions server/services/src/main/java/org/zanata/dao/PersonDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.zanata.model.HLocale;
import org.zanata.model.HLocaleMember;
import org.zanata.model.HPerson;
import org.zanata.model.HProject;

@RequestScoped
public class PersonDAO extends AbstractDAOImpl<HPerson, Long> {
Expand Down Expand Up @@ -120,7 +119,9 @@ public List<HPerson> findAllEnabledContainingName(String name, int maxResult,
query.setMaxResults(maxResult);
}
query.setComment("PersonDAO.findAllEnabledContainingName");
return query.list();
@SuppressWarnings("unchecked")
List<HPerson> results = query.list();
return results;
}

public int getTotalTranslator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.inject.Named;
import org.apache.deltaspike.jpa.api.transaction.Transactional;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zanata.ApplicationConfiguration;
import org.zanata.common.LocaleId;
import org.zanata.dao.AccountDAO;
Expand Down Expand Up @@ -59,6 +61,9 @@ public class UserService implements UserResource {
@Inject
private IdentityManager identityManager;

private static final Logger log =
LoggerFactory.getLogger(UserService.class);

@Override
@CheckLoggedIn
public Response getMyInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -131,7 +132,7 @@ public Response get(@PathParam("configKey") @Nonnull String configKey) {
@PUT
@Path("/c/{configKey}")
public Response put(@PathParam("configKey") @Nonnull String configKey,
String configValue) {
@QueryParam("configValue") String configValue) {
if (!isConfigKeyValid(configKey)) {
return Response.status(Response.Status.BAD_REQUEST)
.entity("config key not supported: " + configKey).build();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Link, Icon } from '../../components'
import { serverUrl } from '../../config'
import { getVersionGroupUrl } from '../../utils/UrlHelper'

const statusIcons = {
ACTIVE: '',
Expand Down Expand Up @@ -31,7 +31,7 @@ const GroupTeaser = ({
<Icon name='users' className='usersicon-muted n1' />
</div>
) : undefined
const link = serverUrl + '/version-group/view/' + details.id
const link = getVersionGroupUrl(details.id)
const className = status !== statusIcons.ACTIVE
? 'text-muted-bold'
: 'text-bold'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Link, Icon } from '../../components'
import { serverUrl } from '../../config'
import { getLanguageUrl } from '../../utils/UrlHelper'

/**
* Entry of Language team search results
Expand All @@ -11,7 +11,7 @@ const LanguageTeamTeaser = ({
details,
...props
}) => {
const link = serverUrl + '/language/view/' + details.id
const link = getLanguageUrl(details.id)
return (
<div className='team-teaser-view' name={name}>
<div className='flex-row'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Link, Icon } from '../../components'
import { serverUrl } from '../../config'
import { getProjectUrl } from '../../utils/UrlHelper'

const statusIcons = {
ACTIVE: '',
Expand Down Expand Up @@ -35,7 +35,7 @@ const ProjectTeaser = ({
</Link>
</div>
)
const link = serverUrl + '/project/view/' + details.id
const link = getProjectUrl(details.id)
const className = status !== statusIcons.ACTIVE
? 'text-muted-bold'
: 'text-bold'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Link, Icon } from '../../components'
import { getProfileUrl } from '../../utils/UrlHelper'

/**
* Entry of User search results
Expand All @@ -15,15 +16,15 @@ const UserTeaser = ({
<Icon className='translateicon-muted' />
{details.wordsTranslated}
</div>)
const url = getProfileUrl(details.id)
return (
<div className='teaser-view-theme' name={name}>
<div className='user-teaser-inner'>
<img
src={details.avatarUrl}
alt={details.id}
className='avatar-round' />
<Link link={'/profile/view/' + details.id}
className='text-bold'>
<Link link={url} className='text-bold'>
{details.description}
</Link>
</div>
Expand Down
Loading

0 comments on commit e3b3edd

Please sign in to comment.