-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1461 from microsoft/feature/vnd-types
adds support for vendor specific content types
- Loading branch information
Showing
13 changed files
with
327 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
abstractions/go/serialization/serialization_writer_factory_registry_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package serialization | ||
|
||
import ( | ||
assert "github.com/stretchr/testify/assert" | ||
"testing" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
type mockSerializer struct { | ||
} | ||
|
||
func (*mockSerializer) WriteStringValue(key string, value *string) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteBoolValue(key string, value *bool) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteByteValue(key string, value *byte) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteInt8Value(key string, value *int8) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteInt32Value(key string, value *int32) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteInt64Value(key string, value *int64) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteFloat32Value(key string, value *float32) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteFloat64Value(key string, value *float64) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteByteArrayValue(key string, value []byte) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteTimeValue(key string, value *time.Time) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteISODurationValue(key string, value *serialization.ISODuration) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteDateOnlyValue(key string, value *serialization.DateOnly) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteTimeOnlyValue(key string, value *serialization.TimeOnly) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteUUIDValue(key string, value *uuid.UUID) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteObjectValue(key string, item serialization.Parsable) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfObjectValues(key string, collection []serialization.Parsable) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfStringValues(key string, collection []string) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfBoolValues(key string, collection []bool) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfByteValues(key string, collection []byte) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfInt8Values(key string, collection []int8) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfInt32Values(key string, collection []int32) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfInt64Values(key string, collection []int64) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfFloat32Values(key string, collection []float32) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfFloat64Values(key string, collection []float64) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfTimeValues(key string, collection []time.Time) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfISODurationValues(key string, collection []serialization.ISODuration) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfDateOnlyValues(key string, collection []serialization.DateOnly) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfTimeOnlyValues(key string, collection []serialization.TimeOnly) error { | ||
return nil | ||
} | ||
func (*mockSerializer) WriteCollectionOfUUIDValues(key string, collection []uuid.UUID) error { | ||
return nil | ||
} | ||
func (*mockSerializer) GetSerializedContent() ([]byte, error) { | ||
return nil, nil | ||
} | ||
func (*mockSerializer) WriteAdditionalData(value map[string]interface{}) error { | ||
return nil | ||
} | ||
func (*mockSerializer) Close() error { | ||
return nil | ||
} | ||
|
||
type mockSerializerFactory struct { | ||
} | ||
|
||
func (*mockSerializerFactory) GetValidContentType() (string, error) { | ||
return "application/json", nil | ||
} | ||
func (*mockSerializerFactory) GetSerializationWriter(contentType string) (serialization.SerializationWriter, error) { | ||
return &mockSerializer{}, nil | ||
} | ||
|
||
func TestItGetsVendorSpecificSerializationWriter(t *testing.T) { | ||
registry := NewSerializationWriterFactoryRegistry() | ||
registry.ContentTypeAssociatedFactories["application/json"] = &mockSerializerFactory{} | ||
serializationWriter = registry.GetSerializationWriter("application/vnd+json") | ||
assert.NotNil(t, serializationWriter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
abstractions/java/lib/src/test/java/com/microsoft/kiota/ParseNodeFactoryRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.microsoft.kiota; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import com.microsoft.kiota.serialization.ParseNodeFactoryRegistry; | ||
import com.microsoft.kiota.serialization.ParseNode; | ||
import com.microsoft.kiota.serialization.ParseNodeFactory; | ||
|
||
class ParseNodeFactoryRegistryTest { | ||
@Test | ||
void getsVendorSpecificParseNodeFactory() throws IOException { | ||
final var registry = new ParseNodeFactoryRegistry(); | ||
final var parseNodeFactoryMock = mock(ParseNodeFactory.class); | ||
final var parseNodeMock = mock(ParseNode.class); | ||
when(parseNodeFactoryMock.getValidContentType()).thenReturn("application/json"); | ||
when(parseNodeFactoryMock.getParseNode(anyString(), any(InputStream.class))).thenReturn(parseNodeMock); | ||
registry.contentTypeAssociatedFactories.put("application/json", parseNodeFactoryMock); | ||
final var str = "{\"test\":\"test\"}"; | ||
try (final var payloadMock = new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8))) { | ||
final var parseNode = registry.getParseNode("application/vnd+json", payloadMock); | ||
assertNotNull(parseNode); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...ns/java/lib/src/test/java/com/microsoft/kiota/SerializationWriterFactoryRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.microsoft.kiota; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.io.IOException; | ||
|
||
import com.microsoft.kiota.serialization.SerializationWriterFactoryRegistry; | ||
import com.microsoft.kiota.serialization.SerializationWriter; | ||
import com.microsoft.kiota.serialization.SerializationWriterFactory; | ||
|
||
class SerializationWriterFactoryRegistryTest { | ||
@Test | ||
void getsVendorSpecificSerializationWriterFactory() throws IOException { | ||
final var registry = new SerializationWriterFactoryRegistry(); | ||
final var serializationWriterFactoryMock = mock(SerializationWriterFactory.class); | ||
final var serializationWriterMock = mock(SerializationWriter.class); | ||
when(serializationWriterFactoryMock.getValidContentType()).thenReturn("application/json"); | ||
when(serializationWriterFactoryMock.getSerializationWriter(anyString())).thenReturn(serializationWriterMock); | ||
registry.contentTypeAssociatedFactories.put("application/json", serializationWriterFactoryMock); | ||
final var parseNode = registry.getSerializationWriter("application/vnd+json"); | ||
assertNotNull(parseNode); | ||
} | ||
} |
Oops, something went wrong.