License and tests with new way to play with extensions
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
a3bab6f860
commit
0d2e1d7579
|
@ -1,6 +1,22 @@
|
|||
/**
|
||||
* Copyright 2019 The CloudEvents 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 io.cloudevents.v03;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
|
@ -10,6 +26,9 @@ import org.junit.Test;
|
|||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.extensions.DistributedTracingExtension;
|
||||
import io.cloudevents.extensions.ExtensionFormat;
|
||||
import io.cloudevents.extensions.InMemoryFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -135,4 +154,54 @@ public class CloudEventBuilderTest {
|
|||
assertEquals("subject", ce.getAttributes().getSubject().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_have_dte() {
|
||||
// setup
|
||||
final DistributedTracingExtension dt = new DistributedTracingExtension();
|
||||
dt.setTraceparent("0");
|
||||
dt.setTracestate("congo=4");
|
||||
|
||||
final ExtensionFormat tracing = new DistributedTracingExtension.Format(dt);
|
||||
|
||||
// act
|
||||
CloudEventImpl<Object> ce =
|
||||
CloudEventBuilder.builder()
|
||||
.withId("id")
|
||||
.withSource(URI.create("/source"))
|
||||
.withType("type")
|
||||
.withExtension(tracing)
|
||||
.build();
|
||||
|
||||
Object actual = ce.getExtensions()
|
||||
.get(DistributedTracingExtension.Format.IN_MEMORY_KEY);
|
||||
|
||||
// assert
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof DistributedTracingExtension);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_have_custom_extension() {
|
||||
String myExtKey = "comexampleextension1";
|
||||
String myExtVal = "value";
|
||||
|
||||
ExtensionFormat custom = ExtensionFormat
|
||||
.of(InMemoryFormat.of(myExtKey, myExtKey, String.class),
|
||||
myExtKey, myExtVal);
|
||||
|
||||
// act
|
||||
CloudEventImpl<Object> ce =
|
||||
CloudEventBuilder.builder()
|
||||
.withId("id")
|
||||
.withSource(URI.create("/source"))
|
||||
.withType("type")
|
||||
.withExtension(custom)
|
||||
.build();
|
||||
|
||||
Object actual = ce.getExtensions()
|
||||
.get(myExtKey);
|
||||
|
||||
assertNotNull(actual);
|
||||
assertTrue(actual instanceof String);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
/**
|
||||
* Copyright 2019 The CloudEvents 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 io.cloudevents.v03;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -15,8 +30,8 @@ import org.junit.rules.ExpectedException;
|
|||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.ExtensionFormat;
|
||||
import io.cloudevents.extensions.DistributedTracingExtension;
|
||||
import io.cloudevents.extensions.ExtensionFormat;
|
||||
import io.cloudevents.json.Json;
|
||||
import io.cloudevents.json.types.Much;
|
||||
|
||||
|
@ -99,7 +114,7 @@ public class CloudEventJacksonTest {
|
|||
dt.setTraceparent("0");
|
||||
dt.setTracestate("congo=4");
|
||||
|
||||
final ExtensionFormat tracing = new DistributedTracingExtension.InMemory(dt);
|
||||
final ExtensionFormat tracing = new DistributedTracingExtension.Format(dt);
|
||||
|
||||
CloudEvent<AttributesImpl, Object> ce =
|
||||
CloudEventBuilder.builder()
|
||||
|
@ -231,7 +246,7 @@ public class CloudEventJacksonTest {
|
|||
|
||||
// assert
|
||||
assertNotNull(ce.getExtensions()
|
||||
.get(DistributedTracingExtension.InMemory.IN_MEMORY_KEY));
|
||||
.get(DistributedTracingExtension.Format.IN_MEMORY_KEY));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue