Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz1124630 - fix according review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Dec 1, 2014
1 parent 3545941 commit 8eb6170
Show file tree
Hide file tree
Showing 20 changed files with 140 additions and 91 deletions.
12 changes: 10 additions & 2 deletions mock-server/pom.xml
Expand Up @@ -152,12 +152,20 @@
<plugin>
<groupId>com.ning.maven.plugins</groupId>
<artifactId>maven-duplicate-finder-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<!-- from jetty dependencies we have a couple about.html -->
<exceptions>
<exception>
<!-- from jetty dependencies we have a couple about.html -->
<resourcePatterns>
<resourcePattern>about.html</resourcePattern>
</resourcePatterns>
</exception>
</exceptions>
<skip>true</skip>

This comment has been minimized.

Copy link
@seanf

seanf Dec 1, 2014

Contributor

We shouldn't need the skip any more.

</configuration>
</plugin>
</plugins>
</build>
</project>


3 changes: 2 additions & 1 deletion pom.xml
Expand Up @@ -225,4 +225,5 @@
<module>zanata-maven-plugin</module>
<module>zanata-rest-client</module>
</modules>
</project>
</project>

Expand Up @@ -50,10 +50,10 @@ public void run() throws Exception {
getOpts().getProj(), getOpts().getProjectVersion());

List<ResourceMeta> list = client.getResourceMeta(null);
ConsoleInteractor console = new ConsoleInteractorImpl();
for (ResourceMeta doc : list) {
console.printfln(doc.getName());
System.out.println(doc.getName());
}
}

}

Expand Up @@ -39,12 +39,12 @@ public class GlossaryDeleteCommand extends
ConfigurableCommand<GlossaryDeleteOptions> {
private static final Logger log = LoggerFactory
.getLogger(GlossaryDeleteCommand.class);
private final GlossaryClient client;
private final GlossaryClient glossaryClient;

public GlossaryDeleteCommand(GlossaryDeleteOptions opts,
RestClientFactory clientFactory) {
super(opts, clientFactory);
client = getClientFactory().getGlossaryClient();
glossaryClient = getClientFactory().getGlossaryClient();
}

public GlossaryDeleteCommand(GlossaryDeleteOptions opts) {
Expand All @@ -59,12 +59,13 @@ public void run() throws Exception {
log.info("Delete entire glossary?: {}", getOpts().getAllGlossary());

if (getOpts().getAllGlossary()) {
client.deleteAll();
glossaryClient.deleteAll();
} else if (!StringUtils.isEmpty(getOpts().getlang())) {
client.delete(new LocaleId(getOpts()
glossaryClient.delete(new LocaleId(getOpts()
.getlang()));
} else {
throw new RuntimeException("Option 'zanata.lang' is required.");
}
}
}

8 changes: 7 additions & 1 deletion zanata-rest-client/pom.xml
Expand Up @@ -133,14 +133,19 @@
<artifactId>guava</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.ning.maven.plugins</groupId>
<artifactId>maven-duplicate-finder-plugin</artifactId>
<version>1.0.7</version>
<configuration>
<checkTestClasspath>false</checkTestClasspath>
</configuration>
Expand All @@ -149,3 +154,4 @@
</build>

</project>

Expand Up @@ -26,6 +26,7 @@

import org.zanata.rest.RestConstant;

import com.google.common.annotations.VisibleForTesting;
import com.sun.jersey.api.client.ClientHandlerException;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
Expand All @@ -50,6 +51,11 @@ public ClientResponse handle(ClientRequest cr)
headers.add(RestConstant.HEADER_USERNAME, username);
headers.add(RestConstant.HEADER_API_KEY, apiKey);
headers.add(RestConstant.HEADER_VERSION_NO, ver);
return handleNext(cr);
}

@VisibleForTesting
protected ClientResponse handleNext(ClientRequest cr) {
return getNext().handle(cr);
}

Expand All @@ -61,3 +67,4 @@ public void setUsername(String username) {
this.username = username;
}
}

Expand Up @@ -55,4 +55,5 @@ public void testPut() throws Exception {

MockServerTestUtil.verifyServerRespondSuccessStatus();
}
}
}

This file was deleted.

@@ -0,0 +1,83 @@
/*
* Copyright 2011, 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.rest.client;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;

import javax.ws.rs.core.MultivaluedHashMap;

import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.zanata.rest.RestConstant;
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;

/**
* @author Sean Flanigan <a
* href="mailto:sflaniga@redhat.com">sflaniga@redhat.com</a>
*
*/
public class ApiKeyHeaderFilterTest {
@Mock
private ClientRequest mockRequest;
@Mock
private ClientResponse response;

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}

@Test
public void testHeaders() throws Exception {
String username = "username";
String apiKey = "apiKey";
String ver = "ver";
ApiKeyHeaderFilter filter =
new ApiKeyHeaderFilter(username, apiKey, ver) {
@Override
protected ClientResponse handleNext(
ClientRequest cr) {
return response;
}
};

MultivaluedHashMap<String, Object> headerMap =
new MultivaluedHashMap<>();
when(mockRequest.getHeaders()).thenReturn(headerMap);
//

filter.handle(mockRequest);

assertThat(headerMap.getFirst(RestConstant.HEADER_USERNAME).toString(),
Matchers.equalTo(username));
assertThat(headerMap.getFirst(RestConstant.HEADER_API_KEY).toString(),
Matchers.equalTo(apiKey));
assertThat(headerMap.getFirst(RestConstant.HEADER_VERSION_NO)
.toString(), Matchers.equalTo(ver));
}
}

Expand Up @@ -79,4 +79,5 @@ public void testGetProcessStatus() throws Exception {
assertThat(processStatus.getStatusCode(), Matchers.equalTo(
ProcessStatus.ProcessStatusCode.Finished));
}
}
}

Expand Up @@ -54,4 +54,5 @@ public void testGetCopyTransStatus() throws Exception {
client.getCopyTransStatus("about-fedora", "master", "Authors");
assertThat(copyTransStatus.isInProgress(), Matchers.is(false));
}
}
}

Expand Up @@ -167,4 +167,5 @@ public void testDownloadTranslationFile() {
Matchers.hasSize(1));
}

}
}

Expand Up @@ -57,4 +57,5 @@ public void testDeleteAll() throws Exception {
client.deleteAll();
MockServerTestUtil.verifyServerRespondSuccessStatus();
}
}
}

Expand Up @@ -56,4 +56,5 @@ public void testPut() throws Exception {
MockServerTestUtil.verifyServerRespondSuccessStatus();
}

}
}

Expand Up @@ -61,4 +61,5 @@ public void testSampleConfig() {

assertThat(config, Matchers.containsString("<project>"));
}
}
}

Expand Up @@ -49,4 +49,5 @@ public void canGetProjects() {
assertThat(projects[0].getId(), Matchers.equalTo("about-fedora"));
}

}
}

Expand Up @@ -43,4 +43,5 @@ public void testGetVersion() {
Matchers.equalTo("3.6.0-SNAPSHOT"));
}

}
}

Expand Up @@ -76,4 +76,5 @@ public void testDeleteResource() {
String result = client.deleteResource("test");
assertThat(result, Matchers.isEmptyOrNullString());
}
}
}

Expand Up @@ -75,4 +75,5 @@ public void testGetContributorStatistics() {
assertThat(statistics, Matchers.hasKey("pahuang"));
}

}
}

Expand Up @@ -56,4 +56,5 @@ public void testGetTranslations() {
assertThat(translations.getTextFlowTargets(), Matchers.hasSize(1));
}

}
}

0 comments on commit 8eb6170

Please sign in to comment.