Fortunately, there's the MongoDB brew tap!
To use this, just:
- Make sure you have Homebrew installed.
- Install the tap: brew tap mongodb/brew
- Install the MongoDB command line: brew install mongodb-community-shell
package org.example.test.app
...imports blah...
@SpringBootApplication()
@Import(SomeConfig::class)
class TestGraphQLClientApp {
/**
* Defines the main resolvers: Query and Mutation.
*/
@Bean
fun resolvers(query: GraphQLQueryResolver) = listOf(query)
}
package org.example.test
... imports blah ...
@RunWith(SpringJUnit4ClassRunner::class)
@SpringBootTest(classes = [TestGraphQLClientApp::class, HttpClientConfiguration::class],
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class GraphQLClientTest {
companion object : KLogging()
@LocalServerPort
private val port: Int = 0
@Autowired
private lateinit var factory: RestTemplateFactory
// These have to be 'by lazy' because Spring will inject the fields they rely on after init.
private val template by lazy { factory.createRestTemplate() }
private val baseUrl by lazy { "http://localhost:$port/graphql" }
private val client by lazy { GraphQLClient(baseUrl, template) }
@Test
fun basicClientTest() {
client.query("query { foo }").also { value ->
logger.info { prettyPrint(value) }
assertEquals("foo", assertHasField(value, "data", "foo").asText())
}
client.query("query { getThing(id: \"12345-ABC\") { one two } }").also {
logger.info { prettyPrint(it) }
}
}
}
@SpringBootApplication(exclude = [
LiquibaseAutoConfiguration::class,
DataSourceAutoConfiguration::class,
DataSourceTransactionManagerAutoConfiguration::class,
HibernateJpaAutoConfiguration::class])
buildscript {
ext {
kotlinVersion = '1.1.2-4'
}
repositories {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies { // Gradle Plugin classpath.
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
}
}
kotlinVersion information over and over.
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
dependencies {
// Kotlin/JVM libraries
compile("org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}")
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:${kotlinVersion}")
compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
// Kotlin SLF4J utility
compile 'io.github.microutils:kotlin-logging:1.4.4'
}
docker build -t test-image --force-rm .
FROM openjdk:8-jre-alpine
EXPOSE 9324
ARG ELASTICMQ_VERSION=0.13.2
CMD ["java", "-jar", "-Dconfig.file=/elasticmq/custom.conf", "/elasticmq/server.jar"]
COPY custom.conf /elasticmq/custom.conf
ADD "https://s3-eu-west-1.amazonaws.com/softwaremill-public/elasticmq-server-${ELASTICMQ_VERSION}.jar" /elasticmq/server.jar
docker build -t=my-elasticmq:${VER} --force-rm --build-arg ELASTICMQ_VERSION=${VER}
Where:docker run -it --rm --entrypoint /bin/bash test-image
RUN apk add --update bash libstdc++ curl zip && \
rm -rf /var/cache/apk/*
# Workaround https://issues.apache.org/jira/browse/GROOVY-7906 and other 'busybox' related issues. RUN rm /bin/sh && ln -s /bin/bash /bin/sh
# Install groovy
# Use curl -L to follow redirects
# Also, use sed to make a workaround for https://issues.apache.org/jira/browse/GROOVY-7906
RUN curl -L https://bintray.com/artifact/download/groovy/maven/apache-groovy-binary-2.4.8.zip -o /tmp/groovy.zip && \
cd /usr/local && \
unzip /tmp/groovy.zip && \
rm /tmp/groovy.zip && \
ln -s /usr/local/groovy-2.4.8 groovy && \
/usr/local/groovy/bin/groovy -v && \
cd /usr/local/bin && \
ln -s /usr/local/groovy/bin/groovy groovy
@Value("${some.setting:8}")
private int mySetting;
8 if the some.settings property is not found. Simple enough, but still... you end up getting this kind of error:org.springframework.beans.factory.BeanCreationException: Error creating bean with name '.... blah blah blah ...'
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private int com.foo.MyBean.mySetting; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert value of type [java.lang.String] to required type [int]; nested exception is java.lang.NumberFormatException: For input string: "${some.setting:8}"
...
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert value of type [java.lang.String] to required type [int]; nested exception is java.lang.NumberFormatException: For input string: "${some.setting:8}"
...
Caused by: java.lang.NumberFormatException: For input string: "${some.setting:8}"
This means that Spring does not know how to interpret the default value expression. To enable the Spring Expression Language in @Value just add PropertySourcesPlaceholderConfigurer to the configuration.
In Java annotations:
@Configuration
public class MyConfig
{
...
@Bean
public static PropertySourcesPlaceholderConfigurer getPropertySourcesPlaceholderConfigurer()
{
return new PropertySourcesPlaceholderConfigurer();
}
...
}
In XML, this is usually not a problem because you've got:
<context:property-placeholder location="classpath:defaults.properties"/>
<bean id="makeOne" class="com.foo.SomeBean" scope="prototype"/>
@Component
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SomeBean
{
...
}
public class MyEvent extends ApplicationEvent
{
private final String message;
public MyEvent(Object source, String message)
{
super(source);
this.message = message;
}
public String getMessage()
{
return message;
}
}
@Component
public class MyEventProducer implements ApplicationEventPublisherAware
{
private ApplicationEventPublisher applicationEventPublisher;
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
{
this.applicationEventPublisher = applicationEventPublisher;
}
public void someBusinessMethod()
{
...
applicationEventPublisher.publishEvent(new MyEvent(this, "Hey! Something happened!"));
...
}
}
@Component
public class MyListener implements ApplicationListener<MyEvent>
{
@Autowired
private SomeBusinessLogic logic;
@Override
@Transactional
public void onApplicationEvent(MyEvent event)
{
logic.doSomething(event.getMessage());
}
}
@Component
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public class RequestBean
{
private final long createdOn = System.currentTimeMillis();
public long getCreatedOn()
{
return createdOn;
}
}
<bean id="thingFactory" class="eg.ThingFactory"/>
<bean id="thing" factory-bean="thingFactory" factory-method="getThing"/>Spring will then call the getThing() method on the ThingFactory to get the instance.
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter()
{
void afterCommit()
{
// ... do stuff ...
}
});
sourceSets {
main {
java {
srcDir 'src'
}
resources {
srcDir 'conf'
}
}
test {
java {
srcDir 'test_src'
}
}
}
task convertIvyDeps << {
def ivyXml = new XmlParser().parse(new File("ivy.xml"))
println "dependencies {"
ivyXml.dependencies.dependency.each {
def scope = it.@conf?.contains("test") ? "testCompile" : "compile"
println("\t$scope \"${it.@org}:${it.@name}:${it.@rev}\"")
}
println "}"
}
ext {
version_junit="4.11"
}
dependencies {
... blah blah blah...
testCompile "junit:junit:${version_junit}"
}
allprojects {
apply plugin: 'java'
group = 'org.jegrid'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url 'http://repository.jboss.org/nexus/content/groups/public'
}
flatDir {
dirs "$rootDir/lib" // If we use just 'lib', the dir will be relative.
}
}
}
lib directory at the top level because they are not in the global Maven repos, or in the JBoss repo. The flatDir closure will allow Gradle to look in this directory to resolve dependencies. task createSourceDirectories << {
sourceSets.all { set -> set.allSource.srcDirs.each {
println "creating $it ... "
it.mkdirs()
}
} }
@Test(expected=java.lang.ArrayIndexOutOfBoundsException.class)
$ sudo yum install fedup
$ sudo yum update fedup fedora-release
$ sudo fedup --network 20
20 is the version you want to upgrade to. Fedup will automatically reboot the system when it's done downloading everything.