Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Merged
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,7 @@ local.properties
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# betamax certificates
*.csr
*.cert
*.jks
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ jdk:
- openjdk7
- oraclejdk7
- oraclejdk8
sudo: false
before_script:
sudo keytool -importcert -keystore $JAVA_HOME/jre/lib/security/cacerts -file betamax.pem -storepass changeit -noprompt
sudo: required
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ open build/jacocoHtml/index.html

[JaCoCo]: https://docs.gradle.org/current/userguide/jacoco_plugin.html

#### Betamax

To be able to run the Betamax-based tests you need to add Betamax's certificate into Java's trust store, `cacerts`:

```
sudo keytool -importcert -keystore $JAVA_HOME/jre/lib/security/cacerts -file betamax.pem -alias betamax -storepass changeit -noprompt
```

It is adviced to remove the certificate after testing is done:

```
sudo keytool -delete -keystore $JAVA_HOME/jre/lib/security/cacerts -alias betamax -storepass changeit -noprompt
```

Note that the temporary files generated by Betamax:

* api.twingly.com.jks
* api.twingly.com.cert
* api.twingly.com.csr
* betamax-local.jks

need to be removed if generated __before__ Betamax's certificate was added to the trust store, tests will fail otherwise.

For more information, check out [Betamax's SSL configuration documentation](https://github.com/betamaxteam/betamax/tree/b65a972d239d1acadd2f9911c3697d263aa20729#ssl-configuration).

### JavaDoc generation

To generate java docs just run gradle task `javadoc`:
Expand Down
25 changes: 25 additions & 0 deletions betamax.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-----BEGIN CERTIFICATE-----
MI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ZIhvcNAQELBQADggEBAKfMLDHVOZID7UvOQkp3
mLCoUivQBWsA6EAZ2O90Vfh87djXrX7sN6VMP6pEZk5lEOgqP7xy//gh8sd5D8gb
YfzTiJRyf9eZ2Ljq9SrjhZJpsSX094nFGXVWXiBR5KfsZEI56K/sQtAPx6J3v2Eh
m1EjZtAvNcNw3oSmgeUbvsEvySL56dd/nwBkTYrZ3l2E1nNg5dR5Lgv8357sfY9X
A3ov7aYHJbmc0JFSWBwGknk5uuipui3mHAa6pw+ltGfxP0ig35vK9VLw3fyJWte6
yZ54qqcJPveuETA2fqqw6gQ6rscOl3kdaFQHYdhnypTK73nRXsEbF5BafUt8kSxd
uEg=
-----END CERTIFICATE-----
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ ext {
cglibVersion = "3.2.0"
objenesisVersion = "2.2"
jaxbVersion = "2.2.11"
betamaxVersion = "2.0.1"
libs = [
jaxb : "org.glassfish.jaxb:jaxb-runtime:$jaxbVersion",
junit : "junit:junit:$junitVersion",
groovy : "org.codehaus.groovy:groovy-all:$groovyVersion",
spock : "org.spockframework:spock-core:$spockVersion",
cglib : "cglib:cglib-nodep:$cglibVersion",
objenesis: "org.objenesis:objenesis:$objenesisVersion"
objenesis: "org.objenesis:objenesis:$objenesisVersion",
betamax : "software.betamax:betamax-junit:$betamaxVersion"
]
buildTime = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
sharedManifest = manifest {
Expand Down Expand Up @@ -54,6 +56,7 @@ repositories {

dependencies {
compile libs.jaxb
testCompile libs.betamax
testCompile libs.junit
testCompile libs.groovy
testCompile libs.spock
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/twingly/search/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ public final class Constants {
* The constant TWINGLY_API_KEY_PROPERTY
*/
public static final String TWINGLY_API_KEY_PROPERTY = "TWINGLY_SEARCH_KEY";
private static final Properties VERSION_PROPERTIES = new Properties();
/**
* The constant VERSION.
*/
public static final String VERSION = VERSION_PROPERTIES.getProperty("version");
public static final String VERSION;
private static final Properties VERSION_PROPERTIES = new Properties();

static {
URL resource = Constants.class.getClassLoader().getResource("version.properties");
assert resource != null;
try (BufferedInputStream bis = new BufferedInputStream(resource.openStream())) {
VERSION_PROPERTIES.load(bis);
VERSION = VERSION_PROPERTIES.getProperty("version");
} catch (Exception e) {
throw new RuntimeException("version.properties was not found or cannot be read", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.twingly.search.client

import com.twingly.search.QueryBuilder
import com.twingly.search.domain.Language
import com.twingly.search.exception.TwinglySearchServerAPIKeyDoesNotExistException
import org.junit.Rule
import software.betamax.Configuration
import software.betamax.TapeMode
import software.betamax.junit.Betamax
import software.betamax.junit.RecorderRule
import spock.lang.Specification

class UrlConnectionClientFunctionSpockTest extends Specification {
private static final String TAPES_STORAGE = "src/test/resources/com/twingly/search/client/tapes";

File f = new File(TAPES_STORAGE);
Configuration configuration = Configuration.builder().tapeRoot(f).sslEnabled(true).build();
@Rule
RecorderRule recorder = new RecorderRule(configuration);

@Betamax(tape = "search for spotify", mode = TapeMode.READ_WRITE)
def "search for spotify"() {
given:
def apiKey = "API_KEY"
def client = new UrlConnectionClient(apiKey);
def searchPattern = "spotify page-size:10";
def query = QueryBuilder.create(searchPattern).documentLanguage(Language.English).build();
when:
def result = client.makeRequest(query);
then:
result != null
result.getNumberOfMatchesReturned() == 10
}

@Betamax(tape = "search without valid API key", mode = TapeMode.READ_WRITE)
def "search without valid api key"() {
given:
def apiKey = "API_KEY"
def client = new UrlConnectionClient(apiKey);
def searchPattern = "some pattern";
def query = QueryBuilder.create(searchPattern).build();
when:
client.makeRequest(query);
then:
thrown(TwinglySearchServerAPIKeyDoesNotExistException)
}
}
Loading