Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
Merge 856e957 into 5e4a38d
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmckenzie committed Oct 16, 2019
2 parents 5e4a38d + 856e957 commit c57388d
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 11 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to

## [Unreleased]

## [2.2.1] - 2019-10-16
### Changed
- Made local copies of UtcClock and Sleeper, as the dependency on utilities that
these classes require confuses Weld on startup, and causes odd Class loading errors
in the container
### Added
- Main method to Bootstrapper to aid debugging

## [2.2.0] - 2019-10-15
### Changed
- Update to framework 6.2.0
Expand Down
8 changes: 3 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<framework-api.version>4.1.0</framework-api.version>
<framework.version>6.2.0</framework.version>
<utilities.version>1.20.2</utilities.version>
<maven-common-bom.version>2.4.0</maven-common-bom.version>
</properties>

Expand Down Expand Up @@ -73,13 +72,12 @@
<groupId>org.wildfly</groupId>
<artifactId>wildfly-client-all</artifactId>
</dependency>

<dependency>
<groupId>uk.gov.justice.utils</groupId>
<artifactId>utilities-core</artifactId>
<version>${utilities.version}</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>


<!-- Test Dependencies -->
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_FAILED;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.framework.command.client.util.UtcClock;
import uk.gov.justice.services.jmx.api.domain.CommandState;
import uk.gov.justice.services.jmx.api.domain.SystemCommandStatus;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import static java.time.Duration.between;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.common.util.Sleeper;
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.framework.command.client.util.Sleeper;
import uk.gov.justice.framework.command.client.util.UtcClock;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,23 @@ public int startContainerAndRun(final String[] args) {
return mainApplication.run(args);
}
}

public static void main(String[] args) {

final String command = "PING";
final String contextName = "people";

final String userName = "admin";
final String password = "admin";


final String[] arguments = {
"-c", command,
"-u", userName,
"-pw", password,
"-cn", contextName
};

new Bootstrapper().startContainerAndRun(arguments);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package uk.gov.justice.framework.command.client.util;

import java.time.ZonedDateTime;

/**
* Interface for clock providers.
*/
public interface Clock {

ZonedDateTime now();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package uk.gov.justice.framework.command.client.util;

import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep;

/**
* Wrapper for Thread.sleep() to allow mocking
*/
public class Sleeper {

/**
* Sleeps for the specified number of milliseconds
* @param milliseconds the duration of the sleep in milliseconds
*/
public void sleepFor(final long milliseconds) {
try {
sleep(milliseconds);
} catch (final InterruptedException unused) {
currentThread().interrupt();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package uk.gov.justice.framework.command.client.util;

import static java.time.ZoneOffset.UTC;

import java.time.ZonedDateTime;

import javax.enterprise.context.ApplicationScoped;

/**
* Implementation of a clock that always generates a {@link ZonedDateTime} in UTC.
*/
@ApplicationScoped
public class UtcClock implements Clock {

@Override
public ZonedDateTime now() {
return ZonedDateTime.now(UTC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static uk.gov.justice.services.jmx.api.domain.CommandState.COMMAND_IN_PROGRESS;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.framework.command.client.util.UtcClock;
import uk.gov.justice.services.jmx.api.domain.SystemCommandStatus;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import static org.mockito.Mockito.when;

import uk.gov.justice.framework.command.client.io.ToConsolePrinter;
import uk.gov.justice.services.common.util.Sleeper;
import uk.gov.justice.services.common.util.UtcClock;
import uk.gov.justice.framework.command.client.util.Sleeper;
import uk.gov.justice.framework.command.client.util.UtcClock;
import uk.gov.justice.services.jmx.api.command.EventCatchupCommand;
import uk.gov.justice.services.jmx.api.command.SystemCommand;
import uk.gov.justice.services.jmx.api.mbean.SystemCommanderMBean;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package uk.gov.justice.framework.command.client.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.junit.Assert.assertThat;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;


@RunWith(MockitoJUnitRunner.class)
public class SleeperTest {

@InjectMocks
private Sleeper sleeper;

@Test
public void shouldSleepForTheRequiredNumberOfMillseconds() throws Exception {

final long sleepTime = 1_000;

final long startTime = System.currentTimeMillis();

sleeper.sleepFor(sleepTime);

final long endTime = System.currentTimeMillis();

assertThat(endTime - startTime, is(greaterThanOrEqualTo(sleepTime)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package uk.gov.justice.framework.command.client.util;

import static java.time.ZoneOffset.UTC;
import static java.time.ZonedDateTime.now;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;

import java.time.ZonedDateTime;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.runners.MockitoJUnitRunner;

/**
* Unit tests for the {@link UtcClock} class.
*/
@RunWith(MockitoJUnitRunner.class)
public class UtcClockTest {

@InjectMocks
private UtcClock clock;

@Test
public void shouldGetANewZonedDateTimeWithCurrentTime() throws Exception {

final ZonedDateTime zonedDateTime = clock.now();

assertThat(zonedDateTime, is(notNullValue()));

assertThat(zonedDateTime.isAfter(now().minusSeconds(2L)), is(true));
assertThat(zonedDateTime.getZone(), is(UTC));
}
}

0 comments on commit c57388d

Please sign in to comment.