Skip to content

Commit

Permalink
DCB-126 Update the version of an application
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-andrzejak committed Aug 29, 2023
1 parent bbfa0bd commit bd93c6f
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LICENSE-THIRD-PARTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Lists of 149 third-party dependencies.
(The Apache Software License, Version 2.0) Java Faker (com.github.javafaker:javafaker:1.0.2 - http://github.com/DiUS/java-faker)
(The Apache Software License, Version 2.0) Generex (com.github.mifmif:generex:1.0.2 - https://github.com/mifmif/Generex/tree/master)
(The Apache Software License, Version 2.0) project ':json-path' (com.jayway.jsonpath:json-path:2.6.0 - https://github.com/jayway/JsonPath)
(Apache License, Version 2.0) appstore-metadata-service (com.lgi.appstore.metadata:appstore-metadata-service:0.1.9-SNAPSHOT - https://spring.io/projects/spring-boot/appstore-metadata-service-parent/appstore-metadata-service)
(Apache License, Version 2.0) appstore-metadata-service (com.lgi.appstore.metadata:appstore-metadata-service:0.1.10-SNAPSHOT - https://spring.io/projects/spring-boot/appstore-metadata-service-parent/appstore-metadata-service)
(Eclipse Distribution License - v 1.0) Old JAXB Runtime (com.sun.xml.bind:jaxb-impl:2.3.3 - https://eclipse-ee4j.github.io/jaxb-ri/jaxb-bundles/jaxb-impl)
(Apache License 2.0) JSON library from Android SDK (com.vaadin.external.google:android-json:0.0.20131108.vaadin1 - http://developer.android.com/sdk)
(The Apache Software License, Version 2.0) HikariCP (com.zaxxer:HikariCP:4.0.3 - https://github.com/brettwooldridge/HikariCP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import static com.lgi.appstore.metadata.test.framework.model.response.Applicatio
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.FIELD_TYPE
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.FIELD_SIZE
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.FIELD_URL
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.FIELD_VERSION
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.FIELD_VISIBLE
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.extract
import static com.lgi.appstore.metadata.test.framework.model.response.ApplicationDetailsPath.field
Expand Down Expand Up @@ -341,7 +342,6 @@ class MaintainerApiFTSpec extends AsmsFeatureSpecBase {
assertThat(field().versions().from(theBody1)).asList().hasSize(2)
assertThat(field().versions().version().from(theBody1)).asList().containsExactly(v2, v1)
assertThat(field().versions().visible().from(theBody1)).asList().containsExactly(v2Visible, v1Visible)
assertThat(field().versions().encryption().from(theBody1)).asList().containsExactly(v2Encryption, v1Encryption)
and: "the body exposes requirements section with dependencies information"
assertThat(field().requirements().dependencies().id().from(theBody1)).asList().containsExactlyInAnyOrder(v1Dependency1Id, v1Dependency2Id)
Expand Down Expand Up @@ -394,7 +394,6 @@ class MaintainerApiFTSpec extends AsmsFeatureSpecBase {
assertThat(field().versions().from(theBody2)).asList().hasSize(2)
assertThat(field().versions().version().from(theBody2)).asList().containsExactly(v2, v1)
assertThat(field().versions().visible().from(theBody2)).asList().containsExactly(v2Visible, v1Visible)
assertThat(field().versions().encryption().from(theBody2)).asList().containsExactly(v2Encryption, v1Encryption)
and: "the body exposes requirements section with dependencies information"
assertThat(field().requirements().dependencies().id().from(theBody2)).asList().containsExactlyInAnyOrder(v2Dependency1Id, v2Dependency2Id)
Expand Down Expand Up @@ -517,6 +516,49 @@ class MaintainerApiFTSpec extends AsmsFeatureSpecBase {
FIELD_OCI_IMAGE_URL | "myregistry.local:5000/testing/before" || "myregistry.local:5000/testing/after"
}
@Unroll
def "update application details value of #field for specific version (non-latest) for param newVersion"() {
given: "developer creates an application with multiple versions"
def appId = randId()
def newVersion = "0.1.200"
Application appV1 = builder().fromDefaults().withId(appId).with(field, valueV1Before).forCreate()
Application appV2 = builder().fromDefaults().withId(appId).withVersion(newVersion).forCreate();
and: "create only one application"
maintainerSteps.createNewApplication_expectSuccess(DEFAULT_DEV_CODE, appV1)
and: "developer gets specific version details"
JsonPath bodyV1Before = maintainerSteps.getApplicationDetails_expectSuccess(DEFAULT_DEV_CODE, appKeyFor(appV1))
assertThat(extract(field).from(bodyV1Before)).describedAs("$field value before update").isEqualTo(valueV1Before)
when: "developer updates application"
ApplicationForUpdate updatedApp = builder().fromExisting(appV1).withVersion(newVersion).with(field, valueV2After).forUpdate()
def responseUpdate = maintainerSteps.updateApplication(DEFAULT_DEV_CODE, appKeyFor(appV1), updatedApp).extract()
def receivedStatusUpdate = responseUpdate.statusCode()
then: "expected response HTTP status should be success"
receivedStatusUpdate == SC_NO_CONTENT
when: "developer gets details of updated application"
JsonPath bodyV2After = maintainerSteps.getApplicationDetails_expectSuccess(DEFAULT_DEV_CODE, appKeyFor(appV2))
then: "application has #field updated with value #valueV1After"
extract(field).from(bodyV2After) == valueV2After
where:
field | valueV1Before || valueV2After // must be different than the defaults
FIELD_VISIBLE | Boolean.TRUE || Boolean.FALSE
FIELD_ENCRYPTION | Boolean.FALSE || Boolean.TRUE
FIELD_NAME | "appNameBefore" || "appNameAfter"
FIELD_DESCRIPTION | "Description Before ąćęłóśżź" || "Description After €\\\\\\\\"
FIELD_CATEGORY | String.valueOf(Category.DEV) || String.valueOf(Category.RESOURCE)
FIELD_TYPE | "typeBefore" || "typeAfter"
FIELD_SIZE | 10000000 || 20000000
FIELD_ICON | "c:\\Icon.before.png" || "//home/alwi/Icon.after"
FIELD_OCI_IMAGE_URL | "myregistry.local:5000/testing/before" || "myregistry.local:5000/testing/after"
FIELD_VERSION | "0.1.100" || "0.1.200"
}
@Unroll
def "deletes application with #behavior"() {
given: "developer creates an application with 2 versions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ public ApplicationForUpdate forUpdate() {
.visible(headerVisible)
.encryption(headerEncryption)
.ociImageUrl(headerOciImageUrl)
.localization(headerLocalizations);
.localization(headerLocalizations)
.version(headerVersion);

return new ApplicationForUpdate()
.header(appHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.jooq.JSONB;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record11;
import org.jooq.Record12;
import org.jooq.Record2;
import org.jooq.SelectJoinStep;
Expand All @@ -62,6 +61,7 @@

import static com.lgi.appstore.metadata.jooq.model.Tables.MAINTAINER;
import static com.lgi.appstore.metadata.jooq.model.tables.Application.APPLICATION;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Primary
@Service("MaintainerPersistentAppsService")
Expand Down Expand Up @@ -422,6 +422,7 @@ public boolean updateApplication(String maintainerCode, String appId, String ver
.set(APPLICATION.TYPE, applicationForUpdate.getHeader().getType())
.set(APPLICATION.SIZE, applicationForUpdate.getHeader().getSize())
.set(APPLICATION.CATEGORY, applicationForUpdate.getHeader().getCategory().toString())
.set(APPLICATION.VERSION, getVersion(version, applicationForUpdate))
.set(APPLICATION.LOCALIZATIONS, JSONB.valueOf(jsonProcessorHelper.writeValueAsString(JsonObjectNames.LOCALIZATIONS, applicationForUpdate.getHeader().getLocalization())))
.set(APPLICATION.PLATFORM, JSONB.valueOf(jsonProcessorHelper.writeValueAsString(JsonObjectNames.PLATFORM, applicationForUpdate.getRequirements().getPlatform())))
.set(APPLICATION.HARDWARE, JSONB.valueOf(jsonProcessorHelper.writeValueAsString(JsonObjectNames.HARDWARE, applicationForUpdate.getRequirements().getHardware())))
Expand Down Expand Up @@ -571,4 +572,10 @@ private String createApplicationUrlFromApplicationRecord(Record applicationMetad
applicationMetadataRecord.get(APPLICATION.OCI_IMAGE_URL))
);
}

private String getVersion(String version, ApplicationForUpdate applicationForUpdate) {
return isNotBlank(applicationForUpdate.getHeader().getVersion())
? applicationForUpdate.getHeader().getVersion()
: version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,10 @@ components:
description: OCI Image URL
example: "myregistry.local:5000/testing/test-image"
pattern: '^(?!\s*$).+' # validate for non-empty string
version:
type: string
description: Version to update (working only with non-latest version)
example: 1.2.3
StbApplicationDetails:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
import com.lgi.appstore.metadata.util.JsonProcessorHelper;
import org.jooq.DSLContext;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
Expand All @@ -58,12 +61,14 @@
import java.util.UUID;
import java.util.stream.Collectors;

import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class PersistentAppsServiceTest extends BaseServiceTest {

private static final String DEFAULT_VERSION = "1.0.0";
private static final String NEW_VERSION = "1.1.0";

private final AppsService appsService;

Expand Down Expand Up @@ -204,8 +209,10 @@ void canUpdateLatestApplication() {
verifyMaintainerApplicationDetails(maintainerApplicationAfterUpdate, maintainerRecord, applicationForUpdate);
}

@Test
void canUpdateApplication() {
@ParameterizedTest
@ValueSource(strings = {DEFAULT_VERSION, NEW_VERSION})
@NullAndEmptySource
void canUpdateApplication(String versionForUpdate) {
final MaintainerRecord maintainerRecord = createRandomMaintainerRecord();
final String maintainerCode = maintainerRecord.getCode();
final Application application = createRandomApplication(maintainerCode);
Expand All @@ -220,7 +227,7 @@ void canUpdateApplication() {
.dependencies(Collections.singletonList(createRandomDependency()))
.features(Collections.singletonList(createRandomFeature()));
applicationForUpdate.setRequirements(updatedRequirements);
final ApplicationHeaderForUpdate applicationHeaderForUpdate = createRandomApplicationHeaderForUpdate(createRandomLocalization());
final ApplicationHeaderForUpdate applicationHeaderForUpdate = createRandomApplicationHeaderForUpdate(createRandomLocalization(), versionForUpdate);
applicationForUpdate.setHeader(applicationHeaderForUpdate);

appsService.updateApplication(maintainerCode, maintainerApplicationHeader.getId(), maintainerApplicationHeader.getVersion(), applicationForUpdate);
Expand Down Expand Up @@ -382,6 +389,10 @@ private MaintainerApplicationHeader createRandomMaintainerApplicationHeader(Loca
}

private ApplicationHeaderForUpdate createRandomApplicationHeaderForUpdate(Localization localization) {
return createRandomApplicationHeaderForUpdate(localization, null);
}

private ApplicationHeaderForUpdate createRandomApplicationHeaderForUpdate(Localization localization, String version) {
return new ApplicationHeaderForUpdate()
.category(Category.APPLICATION)
.description(UUID.randomUUID().toString())
Expand All @@ -392,7 +403,8 @@ private ApplicationHeaderForUpdate createRandomApplicationHeaderForUpdate(Locali
.localization(Collections.singletonList(localization))
.visible(true)
.encryption(false)
.ociImageUrl("UPDATED_OCI_IMAGE_URL");
.ociImageUrl("UPDATED_OCI_IMAGE_URL")
.version(version);
}

private void verifyMaintainerApplicationDetails(Optional<MaintainerApplicationDetails> maybeMaintainerApplicationDetails,
Expand All @@ -412,6 +424,11 @@ private void verifyMaintainerApplicationDetails(Optional<MaintainerApplicationDe
"visible",
"encryption",
"ociImageUrl");
if (isNotBlank(applicationForUpdate.getHeader().getVersion())) {
assertThat(header.getVersion()).isEqualTo(applicationForUpdate.getHeader().getVersion());
} else {
assertThat(header.getVersion()).isEqualTo(DEFAULT_VERSION);
}
final Maintainer maintainer = maintainerApplicationDetails.getMaintainer();
assertThat(maintainer).isNotNull();
assertThat(maintainer.getAddress()).isEqualTo(maintainerRecord.getAddress());
Expand Down
19 changes: 19 additions & 0 deletions charts/index.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#
# If not stated otherwise in this file or this component's LICENSE file the
# following copyright and licenses apply:
#
# Copyright 2023 Liberty Global Technology Services BV
#
# 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.
#

apiVersion: v1
entries:
appstore-metadata-service:
Expand Down

0 comments on commit bd93c6f

Please sign in to comment.