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

# betamax certificates
littleproxy_cert
littleproxy_keystore.jks
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ ext {
cglibVersion = "3.2.0"
objenesisVersion = "2.2"
jaxbVersion = "2.2.11"
betamaxVersion = "2.0.0-alpha-1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is betamaxVersion used for? Seems to me that only betamaxSnapshotVersion is used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walro I think it's left in so we can easily switch back when a proper release of betamax has been made

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I thought it was something like that. I'd like it removed anyway, but we can do it ourselves.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@walro Yeap it was just for simplification of future dependency version change.

betamaxSnapshotVersion = "2.0.0-SNAPSHOT"
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:$betamaxSnapshotVersion"
]
buildTime = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
sharedManifest = manifest {
Expand All @@ -43,10 +46,12 @@ targetCompatibility = 1.7
repositories {
mavenCentral()
jcenter()
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenLocal()
}
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,48 @@
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.ProxyConfiguration
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 = ProxyConfiguration.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