Skip to content

Commit

Permalink
Reformat code
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkhanh-axonivy committed Jul 18, 2024
1 parent 436882d commit e74c899
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 196 deletions.
17 changes: 12 additions & 5 deletions marketplace-service/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Getting Started

### Reference Documentation

For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)
Expand All @@ -9,9 +10,11 @@ For further reference, please consider the following sections:
* [Spring Web](https://docs.spring.io/spring-boot/docs/3.2.5/reference/htmlsingle/index.html#web)

### Guides

The following guides illustrate how to use some features concretely:

* Installing mongodb, and access it as Url mongodb://localhost:27017/, and you can create and name whatever you want ,then you should put them to application.properties
* Installing mongodb, and access it as Url mongodb://localhost:27017/, and you can create and name whatever you want
,then you should put them to application.properties
* You can change the MongoDB configuration in file `application.properties`
```
spring.data.mongodb.host=
Expand All @@ -21,14 +24,18 @@ The following guides illustrate how to use some features concretely:
* Run mvn clean install to build project
* Run mvn test to test all tests
### Access Swagger URL: http://{your-host}/swagger-ui/index.html
### Install Lombok for Eclipse IDE
* Download lombok here https://projectlombok.org/download
* run command "java -jar lombok.jar" then you can access file “eclipse.ini“ in eclipse folder where you install → there is a text like this: -javaagent:C:\Users\tvtphuc\eclipse\jee-2024-032\eclipse\lombok.jar → it means you are successful
* run command "java -jar lombok.jar" then you can access file “eclipse.ini“ in eclipse folder where you install → there
is a text like this: -javaagent:C:\Users\tvtphuc\eclipse\jee-2024-032\eclipse\lombok.jar → it means you are
successful
* Start eclipse
* Import the project then in the eclipse , you should run the command “mvn clean install“
* After that you go to class MarketplaceServiceApplication → right click to main method → click run as → choose Java Application
* After that you go to class MarketplaceServiceApplication → right click to main method → click run as → choose Java
Application
* Then you can send a request in postman
* If you want to run single test in class UserServiceImplTest. You can right-click to method testFindAllUser and right click → select Run as → choose JUnit Test
* If you want to run single test in class UserServiceImplTest. You can right-click to method testFindAllUser and right
click → select Run as → choose JUnit Test
6 changes: 3 additions & 3 deletions marketplace-service/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath />
<relativePath/>
</parent>
<groupId>com.axonivy.market</groupId>
<artifactId>marketplace-service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.axonivy.market.constants;

public class MavenConstants {
private MavenConstants() {}
private MavenConstants() {
}

public static final String SNAPSHOT_RELEASE_POSTFIX = "-SNAPSHOT";
public static final String SPRINT_RELEASE_POSTFIX = "-m";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.axonivy.market.constants;

public class NonStandardProductPackageConstants {
private NonStandardProductPackageConstants() {}
private NonStandardProductPackageConstants() {
}

public static final String PORTAL = "portal";
public static final String MICROSOFT_REPO_NAME = "msgraph-connector";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public class ProductJsonConstants {
public static final String MAVEN_DROPIN_INSTALLER_ID = "maven-dropins";
public static final String MAVEN_DEPENDENCY_INSTALLER_ID = "maven-dependency";

private ProductJsonConstants() {}
private ProductJsonConstants() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.Map;

@RestController
@RequestMapping("/auth")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

@Getter
public enum TypeOption {
ALL("all", ""), CONNECTORS("connectors", "connector"), UTILITIES("utilities", "util"), SOLUTIONS("solutions", "solution"), DEMOS("demos", "demo");
ALL("all", ""), CONNECTORS("connectors", "connector"), UTILITIES("utilities", "util"),
SOLUTIONS("solutions", "solution"), DEMOS("demos", "demo");

private String option;
private String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
public class XmlReaderUtils {
private static final RestTemplate restTemplate = new RestTemplate();

private XmlReaderUtils() {}
private XmlReaderUtils() {
}

public static List<String> readXMLFromUrl(String url) {
List<String> versions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.axonivy.market.enums.SortOption;
import com.axonivy.market.enums.TypeOption;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.model.ProductRating;
import com.axonivy.market.service.ProductService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.axonivy.market.controller;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.axonivy.market.assembler.ProductDetailModelAssembler;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.MavenArtifactVersionModel;
import com.axonivy.market.model.MultilingualismValue;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.service.ProductService;
import com.axonivy.market.service.VersionService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;

import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
Expand All @@ -21,10 +20,9 @@
import java.util.List;
import java.util.Objects;

import com.axonivy.market.assembler.ProductDetailModelAssembler;
import com.axonivy.market.entity.Product;
import com.axonivy.market.model.ProductDetailModel;
import com.axonivy.market.service.ProductService;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class ProductDetailsControllerTest {
Expand All @@ -48,8 +46,8 @@ class ProductDetailsControllerTest {
void testProductDetails() {
Mockito.when(productService.fetchProductDetail(Mockito.anyString())).thenReturn(mockProduct());
Mockito.when(detailModelAssembler.toModel(mockProduct(), null)).thenReturn(createProductMockWithDetails());
ResponseEntity<ProductDetailModel> mockExpectedResult =
new ResponseEntity<>(createProductMockWithDetails(), HttpStatus.OK);
ResponseEntity<ProductDetailModel> mockExpectedResult = new ResponseEntity<>(createProductMockWithDetails(),
HttpStatus.OK);

ResponseEntity<ProductDetailModel> result = productDetailsController.findProductDetails(DOCKER_CONNECTOR_ID);

Expand All @@ -64,11 +62,11 @@ void testProductDetails() {
void testProductDetailsWithVersion() {
Mockito.when(productService.fetchProductDetail(Mockito.anyString())).thenReturn(mockProduct());
Mockito.when(detailModelAssembler.toModel(mockProduct(), TAG)).thenReturn(createProductMockWithDetails());
ResponseEntity<ProductDetailModel> mockExpectedResult =
new ResponseEntity<>(createProductMockWithDetails(), HttpStatus.OK);
ResponseEntity<ProductDetailModel> mockExpectedResult = new ResponseEntity<>(createProductMockWithDetails(),
HttpStatus.OK);

ResponseEntity<ProductDetailModel> result =
productDetailsController.findProductDetailsByVersion(DOCKER_CONNECTOR_ID, TAG);
ResponseEntity<ProductDetailModel> result = productDetailsController.findProductDetailsByVersion(
DOCKER_CONNECTOR_ID, TAG);

assertEquals(HttpStatus.OK, result.getStatusCode());
assertEquals(result, mockExpectedResult);
Expand All @@ -80,10 +78,10 @@ void testProductDetailsWithVersion() {
void testFindProductVersionsById() {
List<MavenArtifactVersionModel> models = List.of(new MavenArtifactVersionModel());
Mockito.when(
versionService.getArtifactsAndVersionToDisplay(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString()))
versionService.getArtifactsAndVersionToDisplay(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString()))
.thenReturn(models);
ResponseEntity<List<MavenArtifactVersionModel>> result =
productDetailsController.findProductVersionsById("protal", true, "10.0.1");
ResponseEntity<List<MavenArtifactVersionModel>> result = productDetailsController.findProductVersionsById("protal",
true, "10.0.1");
Assertions.assertEquals(HttpStatus.OK, result.getStatusCode());
Assertions.assertEquals(1, Objects.requireNonNull(result.getBody()).size());
Assertions.assertEquals(models, result.getBody());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
package com.axonivy.market.factory;

import static com.axonivy.market.constants.CommonConstants.SLASH;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.io.InputStream;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.github.model.Meta;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kohsuke.github.GHContent;
import org.mockito.junit.jupiter.MockitoExtension;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.entity.Product;
import java.io.IOException;
import java.io.InputStream;

import static com.axonivy.market.constants.CommonConstants.SLASH;
import static com.axonivy.market.constants.MetaConstants.META_FILE;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class ProductFactoryTest {
private static final String DUMMY_LOGO_URL =
"https://raw.githubusercontent.com/axonivy-market/market/master/market/connector/amazon-comprehend-connector/logo.png";
private static final String DUMMY_LOGO_URL = "https://raw.githubusercontent.com/axonivy-market/market/master/market/connector/amazon-comprehend-connector/logo.png";

@Test
void testMappingByGHContent() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -102,7 +103,8 @@ void testFindFeedbackByUserIdAndProductId_UserNotFound() {
when(userRepository.findById(nonExistingUserId)).thenReturn(Optional.empty());

// Test and verify exception
assertThrows(NotFoundException.class, () -> feedbackService.findFeedbackByUserIdAndProductId(nonExistingUserId, productId));
assertThrows(NotFoundException.class,
() -> feedbackService.findFeedbackByUserIdAndProductId(nonExistingUserId, productId));

// Verify interactions
verify(userRepository, times(1)).findById(nonExistingUserId);
Expand All @@ -127,7 +129,8 @@ void testUpsertFeedback_NewFeedback() throws NotFoundException {
User u = new User();
u.setId(newFeedbackModel.getUserId());
when(userRepository.findById(newFeedbackModel.getUserId())).thenReturn(Optional.of(u));
when(feedbackRepository.findByUserIdAndProductId(newFeedbackModel.getUserId(), newFeedbackModel.getProductId())).thenReturn(null);
when(feedbackRepository.findByUserIdAndProductId(newFeedbackModel.getUserId(),
newFeedbackModel.getProductId())).thenReturn(null);
when(feedbackRepository.save(any(Feedback.class))).thenReturn(newFeedback);

// Test method
Expand Down Expand Up @@ -157,7 +160,8 @@ void testUpsertFeedback_UpdateFeedback() throws NotFoundException {
User u = new User();
u.setId(existingFeedback.getUserId());
when(userRepository.findById(existingFeedback.getUserId())).thenReturn(Optional.of(u));
when(feedbackRepository.findByUserIdAndProductId(existingFeedback.getUserId(), existingFeedback.getProductId())).thenReturn(existingFeedback);
when(feedbackRepository.findByUserIdAndProductId(existingFeedback.getUserId(),
existingFeedback.getProductId())).thenReturn(existingFeedback);
when(feedbackRepository.save(existingFeedback)).thenReturn(existingFeedback);

// Test method
Expand All @@ -175,7 +179,8 @@ void testUpsertFeedback_UpdateFeedback() throws NotFoundException {
assertEquals(updatedFeedback.getContent(), result.getContent());
assertEquals(updatedFeedback.getRating(), result.getRating());
verify(userRepository, times(1)).findById(existingFeedback.getUserId());
verify(feedbackRepository, times(1)).findByUserIdAndProductId(existingFeedback.getUserId(), existingFeedback.getProductId());
verify(feedbackRepository, times(1)).findByUserIdAndProductId(existingFeedback.getUserId(),
existingFeedback.getProductId());
verify(feedbackRepository, times(1)).save(existingFeedback);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ void testExtractMavenArtifactFromJsonNode() {

createListNodeForDataNoteByName(nodeName);
MavenArtifact mockArtifact = Mockito.mock(MavenArtifact.class);
Mockito.doReturn(mockArtifact).when(axonivyProductRepoServiceImpl).createArtifactFromJsonNode(childNode, null,
isDependency);
Mockito.doReturn(mockArtifact).when(axonivyProductRepoServiceImpl)
.createArtifactFromJsonNode(childNode, null, isDependency);

axonivyProductRepoServiceImpl.extractMavenArtifactFromJsonNode(dataNode, isDependency, artifacts);

Expand All @@ -116,8 +116,8 @@ void testExtractMavenArtifactFromJsonNode() {
nodeName = ProductJsonConstants.PROJECTS;
createListNodeForDataNoteByName(nodeName);

Mockito.doReturn(mockArtifact).when(axonivyProductRepoServiceImpl).createArtifactFromJsonNode(childNode, null,
isDependency);
Mockito.doReturn(mockArtifact).when(axonivyProductRepoServiceImpl)
.createArtifactFromJsonNode(childNode, null, isDependency);

axonivyProductRepoServiceImpl.extractMavenArtifactFromJsonNode(dataNode, isDependency, artifacts);

Expand Down Expand Up @@ -190,8 +190,7 @@ void testGetOrganization() throws IOException {

@Test
void testGetReadmeAndProductContentsFromTag() throws IOException {
String readmeContentWithImage =
"#Product-name\n Test README\n## Demo\nDemo content\n## Setup\nSetup content (image.png)";
String readmeContentWithImage = "#Product-name\n Test README\n## Demo\nDemo content\n## Setup\nSetup content (image.png)";

GHContent mockContent = createMockProductFolderWithProductJson();

Expand All @@ -213,8 +212,7 @@ void testGetReadmeAndProductContentsFromTag() throws IOException {

@Test
void testGetReadmeAndProductContentFromTag_ImageFromFolder() throws IOException {
String readmeContentWithImageFolder =
"#Product-name\n Test README\n## Demo\nDemo content\n## Setup\nSetup content (./images/image.png)";
String readmeContentWithImageFolder = "#Product-name\n Test README\n## Demo\nDemo content\n## Setup\nSetup content (./images/image.png)";

GHContent mockImageFile = mock(GHContent.class);
when(mockImageFile.getName()).thenReturn(ReadmeConstants.IMAGES, IMAGE_NAME);
Expand Down Expand Up @@ -324,9 +322,10 @@ private static InputStream getMockInputStream() {
}

private static InputStream getMockInputStreamWithOutProjectAndDependency() {
String jsonContent = "{\n" + " \"installers\": [\n" + " {\n" + " \"data\": {\n"
+ " \"repositories\": [\n" + " {\n" + " \"url\": \"http://example.com/repo\"\n"
+ " }\n" + " ]\n" + " }\n" + " }\n" + " ]\n" + "}";
String jsonContent =
"{\n" + " \"installers\": [\n" + " {\n" + " \"data\": {\n" + " \"repositories\": [\n"
+ " {\n" + " \"url\": \"http://example.com/repo\"\n" + " }\n" + " ]\n"
+ " }\n" + " }\n" + " ]\n" + "}";
return new ByteArrayInputStream(jsonContent.getBytes(StandardCharsets.UTF_8));
}

Expand Down Expand Up @@ -357,10 +356,10 @@ private GHContent createMockProductFolderWithProductJson() throws IOException {

GHContent mockContent2 = createMockProductJson();

when(ghRepository.getDirectoryContent(CommonConstants.SLASH, RELEASE_TAG))
.thenReturn(List.of(mockContent, mockContent2));
when(ghRepository.getDirectoryContent(DOCUWARE_CONNECTOR_PRODUCT, RELEASE_TAG))
.thenReturn(List.of(mockContent, mockContent2));
when(ghRepository.getDirectoryContent(CommonConstants.SLASH, RELEASE_TAG)).thenReturn(
List.of(mockContent, mockContent2));
when(ghRepository.getDirectoryContent(DOCUWARE_CONNECTOR_PRODUCT, RELEASE_TAG)).thenReturn(
List.of(mockContent, mockContent2));

return mockContent;
}
Expand Down
Loading

0 comments on commit e74c899

Please sign in to comment.