Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,29 @@ public ModelsMap postProcessModels(ModelsMap objs) {
}

// fill src/main/resources/body/*.java to the body of the class.
try (InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream("body/" + codegenModel.name + ".java")) {
if (inputStream != null) {
String src = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
codegenModel.vendorExtensions.put("x-body", indent4(src));
}
} catch (IOException e) {
// do nothing.
}
String body = readPartialBody("body/model/" + codegenModel.name + ".java");
codegenModel.vendorExtensions.put("x-body", body);
}

return modelsMap;
}

private String readPartialBody(String path) {
// fill src/main/resources/body/*.java to the body of the class.
try (InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream(path)) {
if (inputStream != null) {
System.out.println("Partial body file found: " + path);
String src = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8);
return indent4(src);
}
} catch (IOException e) {
// do nothing.
}
System.out.println("Partial body file NOT found: " + path);
return null;
}

@Override
public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs) {
final Map<String, ModelsMap> processed = super.postProcessAllModels(objs);
Expand Down Expand Up @@ -203,6 +212,13 @@ protected ImmutableMap.Builder<String, Mustache.Lambda> addMustacheLambdas() {
.replace("Client", "")
+ "ExceptionBuilder"
);
})
.put("injectbody", (fragment, writer) -> {
String text = fragment.execute();
String body = readPartialBody("body/api/" + text + ".java");
if (body != null) {
writer.write(body);
}
});
}

Expand Down
21 changes: 21 additions & 0 deletions buildSrc/src/main/resources/body/api/LiffClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@Deprecated
default CompletableFuture<Result<GetAllLiffAppsResponse>> liffV1AppsGet() {
return getAllLIFFApps();
}

@Deprecated
default CompletableFuture<Result<Void>> liffV1AppsLiffIdDelete(@Path("liffId") String liffId) {
return deleteLIFFApp(liffId);
}

@Deprecated
default CompletableFuture<Result<Void>> liffV1AppsLiffIdPut(
@Path("liffId") String liffId,
@Body UpdateLiffAppRequest updateLiffAppRequest) {
return updateLIFFApp(liffId, updateLiffAppRequest);
}

@Deprecated
default CompletableFuture<Result<AddLiffAppResponse>> liffV1AppsPost(@Body AddLiffAppRequest addLiffAppRequest) {
return addLIFFApp(addLiffAppRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* Copyright 2023 LINE Corporation
*
* LINE Corporation licenses this file to you 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 com.linecorp.bot.liff.client;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.put;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathTemplate;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.assertj.core.api.Assertions.assertThat;

import java.net.URI;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.slf4j.bridge.SLF4JBridgeHandler;

import com.github.tomakehurst.wiremock.WireMockServer;
import com.ocadotechnology.gembus.test.Arranger;

import com.linecorp.bot.liff.model.AddLiffAppRequest;
import com.linecorp.bot.liff.model.AddLiffAppResponse;
import com.linecorp.bot.liff.model.GetAllLiffAppsResponse;
import com.linecorp.bot.liff.model.UpdateLiffAppRequest;

/**
* line-openapi introduce the breaking change in <a href="https://github.com/line/line-openapi/pull/26">line-openapi#26</a>.
* This test checks this SDK is backward compatible.
*/
@SuppressWarnings("deprecation")
@Timeout(5)
public class LiffClientBackwardCompatibilityTest {
static {
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
}

private WireMockServer wireMockServer;
private LiffClient api;

@BeforeEach
public void setUp() {
wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
wireMockServer.start();
configureFor("localhost", wireMockServer.port());

api = LiffClient.builder("MY_OWN_TOKEN")
.apiEndPoint(URI.create(wireMockServer.baseUrl()))
.build();
}

@AfterEach
public void tearDown() {
wireMockServer.stop();
}

@Test
public void liffV1AppsGetTest() {
stubFor(get(urlPathTemplate("/liff/v1/apps")).willReturn(
aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{}")));

GetAllLiffAppsResponse response = api.liffV1AppsGet().join().body();

assertThat(response).isNotNull();
// TODO: test validations
}

@Test
public void liffV1AppsLiffIdDeleteTest() {
stubFor(delete(urlPathTemplate("/liff/v1/apps/{liffId}")).willReturn(
aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{}")));

String liffId = Arranger.some(String.class);

api.liffV1AppsLiffIdDelete(liffId).join().body();

// TODO: test validations
}

@Test
public void liffV1AppsLiffIdPutTest() {
stubFor(put(urlPathTemplate("/liff/v1/apps/{liffId}")).willReturn(
aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{}")));

String liffId = Arranger.some(String.class);
UpdateLiffAppRequest updateLiffAppRequest = Arranger.some(UpdateLiffAppRequest.class);

api.liffV1AppsLiffIdPut(liffId, updateLiffAppRequest).join().body();

// TODO: test validations
}

@Test
public void liffV1AppsPostTest() {
stubFor(post(urlPathTemplate("/liff/v1/apps")).willReturn(
aResponse()
.withStatus(200)
.withHeader("content-type", "application/json")
.withBody("{}")));

AddLiffAppRequest addLiffAppRequest = Arranger.some(AddLiffAppRequest.class);

AddLiffAppResponse response = api.liffV1AppsPost(addLiffAppRequest).join().body();

assertThat(response).isNotNull();
// TODO: test validations
}

}
1 change: 1 addition & 0 deletions templates/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ public interface {{classname}} {
return new ApiClientBuilder<>(URI.create("{{#lambda.endpoint}}{{classname}}{{/lambda.endpoint}}"), {{classname}}.class, new {{#lambda.exceptionbuilderclassname}}{{classname}}{{/lambda.exceptionbuilderclassname}}());
}
{{/authenticated}}
{{#lambda.injectbody}}{{classname}}{{/lambda.injectbody}}
}
{{/operations}}