Skip to content

Commit

Permalink
Bumps version and adds tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Jul 23, 2024
1 parent 58d43f9 commit d4db102
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
Copy-Item secring.gpg components/serialization/json/ -Verbose
Copy-Item secring.gpg components/serialization/multipart/ -Verbose
Copy-Item secring.gpg components/http/okHttp/ -Verbose
Copy-Item secring.gpg components/bundle/ -Verbose
shell: pwsh
working-directory: ./
- name: Build with Gradle
Expand Down Expand Up @@ -96,6 +97,7 @@ jobs:
Copy-Item secring.gpg components/serialization/json/ -Verbose
Copy-Item secring.gpg components/serialization/multipart/ -Verbose
Copy-Item secring.gpg components/http/okHttp/ -Verbose
Copy-Item secring.gpg components/bundle/ -Verbose
shell: pwsh
working-directory: ./
- name: Build with Gradle
Expand All @@ -122,6 +124,9 @@ jobs:
- name: Publish Release okHttp
run: ./gradlew --no-daemon :components:http:okHttp:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Publish Release bundle
run: ./gradlew --no-daemon :components:bundle:$PUBLISH_TASK -PmavenCentralSnapshotArtifactSuffix=""
working-directory: ./
- name: Release
uses: anton-yurchenko/git-release@v6.0
env:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.2.0] - 2024-07-25

### Changed

- Adds bundle package for Kiota [#1420](https://github.com/microsoft/kiota-java/issues/1420).

## [1.1.14] - 2024-06-10

### Changed
Expand Down
8 changes: 8 additions & 0 deletions components/bundle/gradle/dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.10.3'

// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.mockito:mockito-inline:5.2.0'

implementation 'jakarta.annotation:jakarta.annotation-api:2.1.1'

api project(':components:abstractions')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.microsoft.kiota.bundle;

import com.microsoft.kiota.ApiClientBuilder;
import com.microsoft.kiota.authentication.AuthenticationProvider;
import com.microsoft.kiota.http.ObservabilityOptions;
import com.microsoft.kiota.http.OkHttpRequestAdapter;
import com.microsoft.kiota.serialization.*;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import okhttp3.Call;

/** RequestAdapter implementation for Kiota Bundle */
public class DefaultRequestAdapter extends OkHttpRequestAdapter {

/**
* Instantiates a DefaultRequestAdapter with the provided authentication provider.
* @param authenticationProvider the authentication provider to use for authenticating requests.
*/
public DefaultRequestAdapter(@Nonnull final AuthenticationProvider authenticationProvider) {
this(authenticationProvider, null);
}

/**
* Instantiates a new DefaultRequestAdapter with the provided authentication provider, and the parse node factory.
* @param authenticationProvider the authentication provider to use for authenticating requests.
* @param parseNodeFactory the parse node factory to use for parsing responses.
*/
@SuppressWarnings("LambdaLast")
public DefaultRequestAdapter(
@Nonnull final AuthenticationProvider authenticationProvider,
@Nullable final ParseNodeFactory parseNodeFactory) {
this(authenticationProvider, parseNodeFactory, null);
}

/**
* Instantiates a new DefaultRequestAdapter with the provided authentication provider, parse node factory, and the serialization writer factory.
* @param authenticationProvider the authentication provider to use for authenticating requests.
* @param parseNodeFactory the parse node factory to use for parsing responses.
* @param serializationWriterFactory the serialization writer factory to use for serializing requests.
*/
@SuppressWarnings("LambdaLast")
public DefaultRequestAdapter(
@Nonnull final AuthenticationProvider authenticationProvider,
@Nullable final ParseNodeFactory parseNodeFactory,
@Nullable final SerializationWriterFactory serializationWriterFactory) {
this(authenticationProvider, parseNodeFactory, serializationWriterFactory, null);
}

/**
* Instantiates a new DefaultRequestAdapter with the provided authentication provider, parse node factory, serialization writer factory, and the http client.
* @param authenticationProvider the authentication provider to use for authenticating requests.
* @param parseNodeFactory the parse node factory to use for parsing responses.
* @param serializationWriterFactory the serialization writer factory to use for serializing requests.
* @param client the http client to use for sending requests.
*/
@SuppressWarnings("LambdaLast")
public DefaultRequestAdapter(
@Nonnull final AuthenticationProvider authenticationProvider,
@Nullable final ParseNodeFactory parseNodeFactory,
@Nullable final SerializationWriterFactory serializationWriterFactory,
@Nullable final Call.Factory client) {
this(authenticationProvider, parseNodeFactory, serializationWriterFactory, client, null);
}

/**
* Instantiates a new DefaultRequestAdapter with the provided authentication provider, parse node factory, serialization writer factory, http client and observability options.
* @param authenticationProvider the authentication provider to use for authenticating requests.
* @param parseNodeFactory the parse node factory to use for parsing responses.
* @param serializationWriterFactory the serialization writer factory to use for serializing requests.
* @param client the http client to use for sending requests.
* @param observabilityOptions the observability options to use for sending requests.
*/
@SuppressWarnings("LambdaLast")
public DefaultRequestAdapter(
@Nonnull final AuthenticationProvider authenticationProvider,
@Nullable final ParseNodeFactory parseNodeFactory,
@Nullable final SerializationWriterFactory serializationWriterFactory,
@Nullable final Call.Factory client,
@Nullable final ObservabilityOptions observabilityOptions) {
super(
authenticationProvider,
parseNodeFactory,
serializationWriterFactory,
client,
observabilityOptions);
setupDefaults();
}

private void setupDefaults() {
ApiClientBuilder.registerDefaultSerializer(JsonSerializationWriterFactory::new);
ApiClientBuilder.registerDefaultSerializer(TextSerializationWriterFactory::new);
ApiClientBuilder.registerDefaultSerializer(FormSerializationWriterFactory::new);
ApiClientBuilder.registerDefaultSerializer(MultipartSerializationWriterFactory::new);
ApiClientBuilder.registerDefaultDeserializer(JsonParseNodeFactory::new);
ApiClientBuilder.registerDefaultDeserializer(FormParseNodeFactory::new);
ApiClientBuilder.registerDefaultDeserializer(TextParseNodeFactory::new);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.microsoft.kiota.bundle;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;

import com.microsoft.kiota.authentication.AuthenticationProvider;
import com.microsoft.kiota.serialization.ParseNodeFactoryRegistry;
import com.microsoft.kiota.serialization.SerializationWriterFactoryRegistry;

import org.junit.jupiter.api.Test;

public class BundleTests {
@Test
void throwsErrorNullAuthenticationProvider() throws Exception {
var exception =
assertThrows(NullPointerException.class, () -> new DefaultRequestAdapter(null));
assertEquals("parameter authenticationProvider cannot be null", exception.getMessage());
}

@Test
void serializersAreRegisteredAsExpected() throws Exception {
final var authenticationProviderMock = mock(AuthenticationProvider.class);
var defaultRequestAdapter = new DefaultRequestAdapter(authenticationProviderMock);
assertEquals("", defaultRequestAdapter.getBaseUrl());

// validate
var serializerCount =
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories
.size();
var deserializerCount =
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.size();

assertEquals(4, serializerCount); // four serializers present
assertEquals(3, deserializerCount); // three deserializers present

var serializerKeys =
SerializationWriterFactoryRegistry.defaultInstance.contentTypeAssociatedFactories
.keySet();
var deserializerKeys =
ParseNodeFactoryRegistry.defaultInstance.contentTypeAssociatedFactories.keySet();

assertTrue(serializerKeys.contains("application/json"));
assertTrue(
deserializerKeys.contains(
"application/json")); // Serializer and deserializer present for
// application/json

assertTrue(serializerKeys.contains("text/plain"));
assertTrue(
deserializerKeys.contains(
"text/plain")); // Serializer and deserializer present for text/plain

assertTrue(serializerKeys.contains("application/x-www-form-urlencoded"));
assertTrue(
deserializerKeys.contains(
"application/x-www-form-urlencoded")); // Serializer and deserializer
// present for
// application/x-www-form-urlencoded

assertTrue(
serializerKeys.contains(
"multipart/form-data")); // Serializer present for multipart/form-data
}
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ org.gradle.caching=true

mavenGroupId = com.microsoft.kiota
mavenMajorVersion = 1
mavenMinorVersion = 1
mavenPatchVersion = 14
mavenMinorVersion = 2
mavenPatchVersion = 0
mavenArtifactSuffix =

#These values are used to run functional tests
Expand Down

0 comments on commit d4db102

Please sign in to comment.