Skip to content

Commit

Permalink
Add REST API for integration testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Børlum committed Nov 21, 2011
1 parent 222b541 commit 7bf3e54
Show file tree
Hide file tree
Showing 53 changed files with 920 additions and 593 deletions.
Expand Up @@ -30,6 +30,9 @@
import com.trifork.stamdata.persistence.RecordSpecification.FieldSpecification;
import com.trifork.stamdata.persistence.RecordSpecification.RecordFieldType;

/**
* @author Thomas G. Kristensen <tgk@trifork.com>
*/
public class RecordBuilder
{
private RecordSpecification recordSpecification;
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class RecordFetcher
private final Provider<Connection> connection;

@Inject
RecordFetcher(Provider<Connection> connection)
public RecordFetcher(Provider<Connection> connection)
{
this.connection = connection;
}
Expand Down
Expand Up @@ -30,6 +30,9 @@
import com.google.common.collect.ImmutableList;
import com.trifork.stamdata.Preconditions;

/**
* @author Thomas G. Kristensen <tgk@trifork.com>
*/
public class RecordSpecification
{
private final String table;
Expand Down Expand Up @@ -64,15 +67,15 @@ public FieldSpecification(String name, RecordFieldType type, int length)
this.length = length;
}
}
private List<FieldSpecification> fieldSpecifications;

private final List<FieldSpecification> fields;

private RecordSpecification(String table, String keyColumn)
{
this.table = table;
this.keyColumn = keyColumn;

fieldSpecifications = new ArrayList<FieldSpecification>();
fields = new ArrayList<FieldSpecification>();
}

public static RecordSpecification createSpec(String table, String keyColumn, Object... fieldDefinitions)
Expand All @@ -89,21 +92,21 @@ public static RecordSpecification createSpec(String table, String keyColumn, Obj

FieldSpecification fieldSpecification = new FieldSpecification(name, type, length);

recordSpecification.fieldSpecifications.add(fieldSpecification);
recordSpecification.fields.add(fieldSpecification);
}

return recordSpecification;
}

public Iterable<FieldSpecification> getFieldSpecs()
{
return ImmutableList.copyOf(fieldSpecifications);
return ImmutableList.copyOf(fields);
}

public int acceptedTotalLineLength()
{
int totalLength = 0;
for(FieldSpecification fieldSpecification: fieldSpecifications)
for(FieldSpecification fieldSpecification: fields)
{
totalLength += fieldSpecification.length;
}
Expand All @@ -112,40 +115,41 @@ public int acceptedTotalLineLength()

public boolean conformsToSpecifications(Record record)
{
Preconditions.checkNotNull(record);
Preconditions.checkNotNull(record, "record");

if (record.size() != fieldSpecifications.size())
if (record.size() != fields.size())
{
return false;
}

for (FieldSpecification fieldsSpecification: fieldSpecifications)
for (FieldSpecification fieldsSpecification: fields)
{
if(!record.containsKey(fieldsSpecification.name))
if (!record.containsKey(fieldsSpecification.name))
{
return false;
}
else
{
Object value = record.get(fieldsSpecification.name);

if(fieldsSpecification.type == RecordFieldType.NUMERICAL)
if (fieldsSpecification.type == RecordFieldType.NUMERICAL)
{
if(!(value instanceof Integer))
if (!(value instanceof Integer))
{
return false;
}
}
else if (fieldsSpecification.type == RecordFieldType.ALPHANUMERICAL)
{
if(!(value instanceof String))
if (value != null && !(value instanceof String))
{
return false;
}
else
else if (value != null)
{
String valueAsString = (String) value;
if(valueAsString.length() > fieldsSpecification.length)
String valueAsString = String.valueOf(value);

if (valueAsString.length() > fieldsSpecification.length)
{
return false;
}
Expand Down
Expand Up @@ -43,7 +43,6 @@ public class TestServer
private int port = 8972;
private String warPath = "src/main/webapp/";


public TestServer()
{
server = new Server();
Expand All @@ -58,7 +57,7 @@ public TestServer start() throws Exception
connector.setPort(port);

File war = new File("." , warPath);
Assert.assertTrue(new File(war, "WEB-INF/web.xml").exists());
assertTrue(new File(war, "WEB-INF/web.xml").getAbsolutePath(), new File(war, "WEB-INF/web.xml").exists());
System.out.println("webapp: " + war.getAbsolutePath());

context.setWar(war.getAbsolutePath());
Expand Down Expand Up @@ -100,6 +99,11 @@ public TestServer warPath(String warPath)
return this;
}

public String warPath()
{
return warPath;
}


public void stop() throws Exception
{
Expand Down
77 changes: 39 additions & 38 deletions db/schema.sql
Expand Up @@ -1152,57 +1152,58 @@ CREATE TABLE Yder (
) ENGINE=InnoDB COLLATE=utf8_bin;


CREATE TABLE YderLoebenummer (
YderLoebenummerPID BIGINT(15) AUTO_INCREMENT NOT NULL PRIMARY KEY ,
Loebenummer BIGINT(12) NOT NULL
) ENGINE=InnoDB COLLATE=utf8_bin;


CREATE TABLE Yderregister (
YderregisterPID BIGINT(15) AUTO_INCREMENT NOT NULL PRIMARY KEY,

Nummer VARCHAR(30) NOT NULL,

Telefon VARCHAR(10),
Navn VARCHAR(256),
Vejnavn VARCHAR(100),
Postnummer VARCHAR(10),
Bynavn VARCHAR(30),
AmtNummer BIGINT(12),
Email VARCHAR(100),
Www VARCHAR(100),
HovedSpecialeKode VARCHAR(100),
HovedSpecialeTekst VARCHAR(100),
HistID VARCHAR(100),

CreatedDate DATETIME NOT NULL,
PID BIGINT(15) AUTO_INCREMENT NOT NULL PRIMARY KEY,

HistIdYder VARCHAR(16) NOT NULL,

AmtKodeYder VARCHAR(2),
AmtTxtYder VARCHAR(60),
YdernrYder VARCHAR(6),
PrakBetegn VARCHAR(50),
AdrYder VARCHAR(50),
PostnrYder VARCHAR(4),
PostdistYder VARCHAR(20),
TilgDatoYder VARCHAR(8),
AfgDatoYder VARCHAR(8),

HvdSpecKode VARCHAR(2),
HvdSpecTxt VARCHAR(60),
HvdTlf VARCHAR(8),

EmailYder VARCHAR(50),
WWW VARCHAR(78),

ModifiedDate DATETIME NOT NULL,
ValidFrom DATETIME NOT NULL,
ValidTo DATETIME NOT NULL,
ValidTo DATETIME,

INDEX (YderregisterPID, ModifiedDate),
INDEX (Nummer, ValidTo, ValidFrom)
INDEX (PID, ModifiedDate),
INDEX (HistIdYder, ValidTo, ValidFrom)
) ENGINE=InnoDB COLLATE=utf8_bin;


CREATE TABLE YderregisterPerson (
YderregisterPersonPID BIGINT(15) AUTO_INCREMENT NOT NULL PRIMARY KEY,
PID BIGINT(15) AUTO_INCREMENT NOT NULL PRIMARY KEY,

Id VARCHAR(20) NOT NULL, -- Consists of CPR + Nummer (TODO: Strange that Nummer is 30 long?)

Nummer VARCHAR(30) NOT NULL,
CPR CHAR(10),
personrolleKode CHAR(2),
personrolleTxt VARCHAR(200),
HistIDPerson VARCHAR(100),
HistIdPerson VARCHAR(16) NOT NULL,

YdernrPerson VARCHAR(6) NOT NULL,

TilgDatoPerson CHAR(8) NOT NULL,
AfgDatoPerson CHAR(8),

CprNr CHAR(10) NOT NULL,

PersonrolleKode CHAR(2),
PersonrolleTxt VARCHAR(60),

CreatedDate DATETIME NOT NULL,
ModifiedDate DATETIME NOT NULL,
ValidFrom DATETIME NOT NULL,
ValidTo DATETIME NOT NULL,
ValidTo DATETIME,

INDEX (YderregisterPersonPID, ModifiedDate),
INDEX (Id, ValidTo, ValidFrom)
INDEX (PID, ModifiedDate),
INDEX (HistIdPerson, ValidTo, ValidFrom)
) ENGINE=InnoDB COLLATE=utf8_bin;


Expand Down
20 changes: 20 additions & 0 deletions dodi/data-manager/pom.xml
Expand Up @@ -144,10 +144,30 @@
<version>6.1.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.9.1</version>
</dependency>

<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-guice</artifactId>
<version>1.9.1</version>
</dependency>

<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.9.1</version>
</dependency>

</dependencies>
Expand Down
Expand Up @@ -31,6 +31,7 @@
import com.google.inject.servlet.GuiceServletContextListener;
import com.trifork.stamdata.importer.jobs.JobManager;
import com.trifork.stamdata.importer.parsers.ParserScheduler;
import com.trifork.stamdata.importer.webinterface.WebInterfaceModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -124,6 +125,6 @@ public void contextDestroyed(ServletContextEvent servletContextEvent)
@Override
protected Injector getInjector()
{
return injector = Guice.createInjector(Stage.PRODUCTION, new ComponentModule());
return injector = Guice.createInjector(Stage.PRODUCTION, new ComponentModule(), new WebInterfaceModule());
}
}
Expand Up @@ -24,27 +24,18 @@
*/
package com.trifork.stamdata.importer;

import com.google.common.collect.ImmutableSet;
import com.google.inject.Scopes;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.google.inject.servlet.ServletModule;
import com.trifork.stamdata.ComponentMonitor;
import com.trifork.stamdata.MonitoringModule;
import com.trifork.stamdata.importer.config.ConfigurationLoader;
import com.trifork.stamdata.importer.config.OldParserContext;
import com.trifork.stamdata.importer.config.ParserConfiguration;
import com.trifork.stamdata.importer.jobs.JobManager;
import com.trifork.stamdata.importer.parsers.ParserContext;
import com.trifork.stamdata.importer.parsers.ParserScheduler;
import com.trifork.stamdata.importer.parsers.ParserModule;
import com.trifork.stamdata.importer.webinterface.DataManagerComponentMonitor;
import com.trifork.stamdata.importer.webinterface.GUIServlet;
import com.trifork.stamdata.importer.parsers.ParserScheduler;
import com.trifork.stamdata.importer.parsers.annotations.InboxRootPath;
import org.apache.commons.configuration.CompositeConfiguration;

import java.util.Set;
import java.io.File;

import static com.trifork.stamdata.importer.config.ParserConfiguration.bindOldParsers;
import static com.trifork.stamdata.importer.config.ParserConfiguration.bindParsers;

/**
Expand All @@ -55,28 +46,22 @@ public class ComponentModule extends ServletModule
@Override
protected void configureServlets()
{
install(new ParserModule());

final CompositeConfiguration config = ConfigurationLoader.loadConfiguration();

// Bind the configured parsers.
// TODO: The parsers' classes should not be named in the configuration file.
//
bindParsers(config, binder());
bindOldParsers(config, binder());


// HACK: Because we are not using the shared ConfigurationLoader (yet!) we cannot easily bind properties
// to named constants.
//
bindConstant().annotatedWith(Names.named("rootDir")).to(config.getString("rootDir"));
String rootDir = config.getString("rootDir");

bindConstant().annotatedWith(InboxRootPath.class).to(rootDir);
bindConstant().annotatedWith(Names.named("file.stabilization.period")).to(config.getInt("file.stabilization.period"));

// Serve the status servlet.
// Bind the configured parsers.
// TODO: The parsers' classes should not be named in the configuration file.
//
bind(ComponentMonitor.class).to(DataManagerComponentMonitor.class);
install(new MonitoringModule());
bindParsers(config, new File(rootDir), binder());

serve("/").with(GUIServlet.class);
install(new ParserModule());

// Bind the services.
//
Expand Down
Expand Up @@ -59,7 +59,7 @@ public class MySqlKeyValueStore implements KeyValueStore
* Thrown if the database is unreachable.
*/
@Inject
MySqlKeyValueStore(@DataOwnerId String dataOwnerId, Connection connection) throws SQLException
MySqlKeyValueStore(@OwnerIdentifier String dataOwnerId, Connection connection) throws SQLException
{
this.connection = checkNotNull(connection, "connection");
checkArgument(connection.getTransactionIsolation() != Connection.TRANSACTION_NONE, "The connection must have an active transaction.");
Expand Down
Expand Up @@ -34,4 +34,4 @@
@BindingAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD})
public @interface DataOwnerId {}
public @interface OwnerIdentifier {}

0 comments on commit 7bf3e54

Please sign in to comment.