Skip to content

Commit

Permalink
#1330 Remove the tests
Browse files Browse the repository at this point in the history
Removed the tests related to verify the behaviour of Jackson as they just add time it takes Micronaut to build.
  • Loading branch information
puneetbehl committed Mar 11, 2019
1 parent 234d067 commit aefdb47
Showing 1 changed file with 0 additions and 274 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode
import groovy.transform.ToString
import io.micronaut.context.ApplicationContext
import io.micronaut.context.DefaultApplicationContext
import io.micronaut.context.env.PropertySource
import org.reactivestreams.Subscriber
import org.reactivestreams.Subscription
import spock.lang.AutoCleanup
Expand Down Expand Up @@ -106,223 +105,6 @@ class JacksonProcessorSpec extends Specification {
foo.age == 10
}

void "test Jackson polymorphic deserialization"() {
given:
ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper)
JacksonProcessor processor = new JacksonProcessor()
Bicycle bicycle = new MountainBike(3, 30, 10)
Garage instance = new Garage(bicycle: bicycle)

when:
def string = objectMapper.writeValueAsString(instance)
byte[] bytes = objectMapper.writeValueAsBytes(instance)
boolean complete = false
JsonNode node = null
Throwable error = null
int nodeCount = 0
processor.subscribe(new Subscriber<JsonNode>() {
@Override
void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE)
}

@Override
void onNext(JsonNode jsonNode) {
nodeCount++
node = jsonNode
}

@Override
void onError(Throwable t) {
error = t
}

@Override
void onComplete() {
complete = true
}
})
processor.onSubscribe(new Subscription() {
@Override
void request(long n) {

}

@Override
void cancel() {

}
})
processor.onNext(bytes)
processor.onComplete()

then:
complete
node != null
error == null
nodeCount == 1
string == '{"bicycle":{"gear":3,"speed":30,"seatHeight":10}}'

when:
Garage garage = objectMapper.treeToValue(node, Garage)

then:
!(garage.bicycle instanceof MountainBike)
}

void "test Jackson polymorphic deserialization, per class"() {
given:
ObjectMapper objectMapper = applicationContext.getBean(ObjectMapper)
JacksonProcessor processor = new JacksonProcessor()
Dog dog = new Dog(name: "Daisy", barkVolume: 1111.1D)
Zoo instance = new Zoo(animal: dog)

when:
def string = objectMapper.writeValueAsString(instance)
byte[] bytes = objectMapper.writeValueAsBytes(instance)
boolean complete = false
JsonNode node = null
Throwable error = null
int nodeCount = 0
processor.subscribe(new Subscriber<JsonNode>() {
@Override
void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE)
}

@Override
void onNext(JsonNode jsonNode) {
nodeCount++
node = jsonNode
}

@Override
void onError(Throwable t) {
error = t
}

@Override
void onComplete() {
complete = true
}
})
processor.onSubscribe(new Subscription() {
@Override
void request(long n) {

}

@Override
void cancel() {

}
})
processor.onNext(bytes)
processor.onComplete()

then:
complete
node != null
error == null
nodeCount == 1
string == '{"animal":{"@class":"io.micronaut.jackson.parser.Dog","name":"Daisy","barkVolume":1111.1}}'

when:
Zoo zoo = objectMapper.treeToValue(node, Zoo)

then:
zoo.animal instanceof Dog

when:
Dog animal = (Dog) zoo.animal

then:
animal != null
animal.name == "Daisy"
animal.barkVolume == 1111.1D
}

void "test Jackson polymorphic deserialization, global default typing"() {
given:
ApplicationContext applicationContext1 = new DefaultApplicationContext("test")
applicationContext1.environment.addPropertySource(PropertySource.of(
'test', ['jackson.defaultTyping':'NON_FINAL']
))
applicationContext1 = applicationContext1.start()
ObjectMapper objectMapper = applicationContext1.getBean(ObjectMapper)
JacksonProcessor processor = new JacksonProcessor()
Bicycle bicycle = new MountainBike(3, 30, 10)
Garage instance = new Garage(bicycle: bicycle)

when:
def string = objectMapper.writeValueAsString(instance)
byte[] bytes = objectMapper.writeValueAsBytes(instance)
boolean complete = false
JsonNode node = null
Throwable error = null
int nodeCount = 0
processor.subscribe(new Subscriber<JsonNode>() {
@Override
void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE)
}

@Override
void onNext(JsonNode jsonNode) {
nodeCount++
node = jsonNode
}

@Override
void onError(Throwable t) {
error = t
}

@Override
void onComplete() {
complete = true
}
})
processor.onSubscribe(new Subscription() {
@Override
void request(long n) {

}

@Override
void cancel() {

}
})
processor.onNext(bytes)
processor.onComplete()

then:
complete
node != null
error == null
nodeCount == 1
string == '["io.micronaut.jackson.parser.Garage",{"bicycle":["io.micronaut.jackson.parser.MountainBike",{"gear":3,"speed":30,"seatHeight":10}]}]'

when:
Garage garage = objectMapper.treeToValue(node, Garage)

then:
garage.bicycle instanceof MountainBike

when:
MountainBike mountainBike = (MountainBike) garage.bicycle

then:
mountainBike != null
mountainBike.gear == 3
mountainBike.speed == 30
mountainBike.seatHeight == 10

cleanup:
applicationContext1.close()
}

void "test publish JSON array async"() {

given:
Expand Down Expand Up @@ -508,59 +290,3 @@ class Foo {
String name
Integer age
}

@ToString
class Garage {
String name
Bicycle bicycle
}

@ToString
class Bicycle {
int gear
int speed

Bicycle() {}

Bicycle(int gear, int speed) {
this.gear = gear
this.speed = speed
}

void applyBrake(int decrement) {
speed -= decrement
}

void speedUp(int increment) {
speed += increment
}
}

@ToString
class MountainBike extends Bicycle {
int seatHeight

MountainBike() {}

MountainBike(int gear,int speed, int seatHeight) {
super(gear, speed)
this.seatHeight = seatHeight
}
}

@ToString
class Zoo {
Animal animal
}

@ToString
@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
class Animal {
String name
}

@ToString
class Dog extends Animal {
double barkVolume

}

0 comments on commit aefdb47

Please sign in to comment.