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
*.jks
*.jks.cert
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ jdk:
- oraclejdk7
- oraclejdk8
sudo: false
script: ./gradlew --debug check
addons:
apt:
packages:
- haveged
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"
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
51 changes: 51 additions & 0 deletions src/test/groovy/com/twingly/search/client/SSLOverriderSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2011 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.twingly.search.client

import software.betamax.proxy.ssl.DummyJVMSSLSocketFactory
import software.betamax.util.SSLOverrider
import spock.lang.Specification

import java.security.Security

import static software.betamax.util.SSLOverrider.SSL_SOCKET_FACTORY_PROVIDER

class SSLOverriderSpec extends Specification {

SSLOverrider sslOverrider = new SSLOverrider()

void 'overrides SSL settings when activated'() {
when:
sslOverrider.activate()

then:
Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER) == DummyJVMSSLSocketFactory.name

cleanup:
sslOverrider.deactivate()
}

void 'restores original SSL settings when deactivated'() {
when:
sslOverrider.activate()
sslOverrider.deactivate()

then:
Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER) == old(Security.getProperty(SSL_SOCKET_FACTORY_PROVIDER))
}

}
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_ONLY)
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_ONLY)
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