Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.
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
3 changes: 3 additions & 0 deletions fluent-tests/prepare-tests.bat
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ if %errorlevel% neq 0 exit /b %errorlevel%
CALL autorest --version=%AUTOREST_CORE_VERSION% %FLUENTLITE_ARGUMENTS% --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/resources/resource-manager/readme.md --tag=package-policy-2020-09 --java.namespace=com.azure.mgmtlitetest.policy
if %errorlevel% neq 0 exit /b %errorlevel%

CALL autorest --version=%AUTOREST_CORE_VERSION% %FLUENTLITE_ARGUMENTS% --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/botservice/resource-manager/readme.md --tag=package-preview-2021-05 --java.namespace=com.azure.mgmtlitetest.botservice
if %errorlevel% neq 0 exit /b %errorlevel%

REM CALL autorest --version=%AUTOREST_CORE_VERSION% %FLUENTLITE_ARGUMENTS% --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/network/resource-manager/readme.md --tag=package-2020-06 --java.namespace=com.azure.mgmtlitetest.network
REM CALL autorest --version=%AUTOREST_CORE_VERSION% %FLUENTLITE_ARGUMENTS% --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/main/specification/compute/resource-manager/readme.md --tag=package-2020-06-30 --java.namespace=com.azure.mgmtlitetest.compute

Expand Down
13 changes: 13 additions & 0 deletions fluent-tests/src/test/java/com/azure/mgmttest/RuntimeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.azure.mgmtlitetest.advisor.AdvisorManager;
import com.azure.mgmtlitetest.advisor.models.ResourceRecommendationBase;
import com.azure.mgmtlitetest.advisor.models.SuppressionContract;
import com.azure.mgmtlitetest.botservice.models.Site;
import com.azure.mgmtlitetest.mediaservices.MediaServicesManager;
import com.azure.mgmtlitetest.mediaservices.models.MediaService;
import com.azure.mgmtlitetest.mediaservices.models.StorageAccountType;
Expand Down Expand Up @@ -148,6 +149,18 @@ public void testPom() throws ParserConfigurationException, IOException, SAXExcep
Assertions.assertTrue(rootTags.get("name").contains("Azure SDK"));
}

@Test
public void testBotservice() throws IOException {
String siteName = "testSiteName";
Site site = new Site().withSiteName(siteName);
Assertions.assertEquals(siteName, site.siteName());

SerializerAdapter serializerAdapter = SerializerFactory.createDefaultManagementSerializerAdapter();
String json = serializerAdapter.serialize(site, SerializerEncoding.JSON);
Site siteFromJson = serializerAdapter.deserialize(json, Site.class, SerializerEncoding.JSON);
Assertions.assertEquals(siteName, siteFromJson.siteName());
}
Comment thread
weidongxu-microsoft marked this conversation as resolved.

@Test
@Disabled("live test")
public void testStorage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static class MockFluentGen extends FluentGen {
DEFAULT_SETTINGS.put("generate-client-interfaces", true);
DEFAULT_SETTINGS.put("required-parameter-client-methods", true);
DEFAULT_SETTINGS.put("generate-samples", true);

DEFAULT_SETTINGS.put("model-override-setter-from-superclass", true);
//DEFAULT_SETTINGS.put("client-flattened-annotation-target", "NONE");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/


package com.azure.autorest.fluent.template;

import com.azure.autorest.extension.base.model.codemodel.CodeModel;
import com.azure.autorest.extension.base.plugin.JavaSettings;
import com.azure.autorest.fluent.FluentGenAccessor;
import com.azure.autorest.fluent.TestUtils;
import com.azure.autorest.mapper.ClientMapper;
import com.azure.autorest.model.clientmodel.Client;
import com.azure.autorest.model.clientmodel.ClientModel;
import com.azure.autorest.model.clientmodel.ClientModelPropertyAccess;
import com.azure.autorest.model.clientmodel.ClientModelPropertyReference;
import com.azure.core.util.CoreUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.util.List;

public class ModelTemplateTests {

private final JavaSettings settings = JavaSettings.getInstance();
private static FluentGenAccessor fluentGenAccessor;

@BeforeAll
public static void init(){
TestUtils.MockFluentGen fluentgen = new TestUtils.MockFluentGen();
fluentGenAccessor = new FluentGenAccessor(fluentgen);
}

/**
* Issue: https://github.com/Azure/autorest.java/issues/1320
* Remove duplicate setter methods from child schema when parent schema contains same property
* mainly to test {@link com.azure.autorest.template.ModelTemplate#getParentSettersToOverride(ClientModel, JavaSettings, List)}
*/
@Test
public void deduplicateTest(){
CodeModel codeModel = TestUtils.loadCodeModel(fluentGenAccessor, "code-model-fluentnamer-botservice.yaml");
Client client = ClientMapper.getInstance().map(codeModel);
ClientModel model = client.getModels().stream().filter(clientModel -> clientModel.getName().equals("Site")).findAny().get();
ModelTemplateAccessor templateAccessor = new ModelTemplateAccessor();
List<ClientModelPropertyReference> propertyReferences = templateAccessor.getClientModelPropertyReferences0(model);
if (!CoreUtils.isNullOrEmpty(model.getPropertyReferences())) {
propertyReferences.addAll(model.getPropertyReferences());
}
// real test here
List<ClientModelPropertyAccess> toOverride = templateAccessor.getParentSettersToOverride(model, settings, propertyReferences);
Assertions.assertEquals(toOverride.size(), 1);
}

private static class ModelTemplateAccessor extends FluentModelTemplate {

public List<ClientModelPropertyReference> getClientModelPropertyReferences0(ClientModel model) {
return super.getClientModelPropertyReferences(model);
}

public List<ClientModelPropertyAccess> getParentSettersToOverride(ClientModel model, JavaSettings settings, List<ClientModelPropertyReference> propertyReferences) {
return super.getParentSettersToOverride(model, settings, propertyReferences);
}

}


}
Loading