From b0ad96bd7932d9e45c77d25f0360b18c738bf658 Mon Sep 17 00:00:00 2001 From: "Carlos E. Feria Vila" Date: Mon, 25 Apr 2022 12:35:16 +0200 Subject: [PATCH] Tener distribution unitaria (#232) * Use single distribution * Corregir CI y maven profiles * Change whoami resource location * Change images configuration * Remove comment space * Change profiles --- .github/workflows/ci.yml | 6 +- ...pr-build-container-images-comment-boot.yml | 82 -------------- .../workflows/pr-build-container-images.yml | 18 +-- .github/workflows/release.yml | 33 ++---- .github/workflows/snapshots.yml | 35 ++---- docker-compose.yml | 52 ++++++++- docker-compose_enterprise.yml | 92 --------------- jreleaser.yml | 6 +- pom.xml | 42 ++----- .../assembly/{enterprise => }/assembly.xml | 2 +- .../assembly/enterprise/native-assembly.xml | 59 ---------- .../{standalone => }/native-assembly.xml | 2 +- src/main/assembly/standalone/assembly.xml | 60 ---------- .../{enterprise => }/application.properties | 24 ++-- .../config/standalone/application.properties | 31 ----- .../openubl/searchpe/models/FilterBean.java} | 26 +++-- .../models/jpa/ContribuyenteRepository.java | 93 +++++++++++---- .../resources/ContribuyenteResource.java | 80 ++++--------- .../resources/CurrentUserResource.java | 34 ------ .../searchpe/resources/FrontendResource.java | 19 +++- .../searchpe/resources/WhoAmIResource.java | 73 ++++++++++++ .../HTTPBasicAuthEnabledInterceptor.java | 14 ++- .../security/DisabledAuthController.java | 40 +++++++ .../application-enterprise.properties | 43 ------- src/main/resources/application.properties | 45 +++++++- src/main/webapp/src/App.tsx | 11 +- src/main/webapp/src/Constants.ts | 10 +- src/main/webapp/src/Routes.tsx | 9 +- .../webapp/src/api-client/resources/core.ts | 2 +- src/main/webapp/src/api/models.tsx | 1 + .../pages/contribuyentes/contribuyentes.tsx | 4 +- .../webapp/src/pages/profile/overview.tsx | 17 ++- src/main/webapp/src/queries/currentUser.ts | 26 +---- src/main/webapp/src/queries/whoami.ts | 22 ++++ .../HeaderApp/BasicMenuDropdownItems.tsx | 29 ----- .../components/layout/HeaderApp/HeaderApp.tsx | 4 +- .../HeaderApp/OidcMenuDropdownItems.tsx | 18 --- .../components/layout/HeaderApp/SSOMenu.tsx | 62 ---------- .../layout/HeaderApp/UserDropdown.tsx | 86 ++++++++++++++ .../layout/SidebarApp/SidebarApp.tsx | 26 ++--- .../hooks/usePermission/usePermission.ts | 18 ++- .../openubl/searchpe/AbstractBaseTest.java | 2 +- ...eManager.java => BasicProfileManager.java} | 7 +- ...anager.java => DefaultProfileManager.java} | 7 +- .../openubl/searchpe/FlywayTestCallback.java | 75 ------------ .../openubl/searchpe/ProfileManager.java | 34 +----- .../ValidPermissionValidatorTest.java | 4 +- ...st.java => ContribuyenteResourceTest.java} | 9 +- ...a => ContribuyenteSearchResourceTest.java} | 8 +- ...Test.java => CurrentUserResourceTest.java} | 19 +++- .../EnterpriseContribuyenteResourceTest.java | 27 ----- .../EnterpriseCurrentUserResourceTest.java | 43 ------- .../resources/EnterpriseUserResourceTest.java | 107 ------------------ ...tiveEnterpriseContribuyenteResourceIT.java | 25 ---- ...NativeEnterpriseCurrentUserResourceIT.java | 25 ---- .../NativeEnterpriseVersionResourceIT.java | 25 ---- ...tiveStandaloneContribuyenteResourceIT.java | 25 ---- ...NativeStandaloneCurrentUserResourceIT.java | 25 ---- .../NativeStandaloneVersionResourceIT.java | 25 ---- .../StandaloneContribuyenteResourceTest.java | 27 ----- ...daloneSearchContribuyenteResourceTest.java | 46 -------- .../StandaloneVersionResourceTest.java | 27 ----- ...esourceTest.java => UserResourceTest.java} | 9 +- ...urceTest.java => VersionResourceTest.java} | 9 +- ...ourceTest.java => WhoAmIResourceTest.java} | 19 ++-- .../searchpe/utils/DataHelperTest.java | 4 +- ...unit.callback.QuarkusTestAfterEachCallback | 1 - ...nit.callback.QuarkusTestBeforeEachCallback | 1 - .../V9999.0.1__test.sql | 0 .../V9999.0.1__test.sql | 0 70 files changed, 606 insertions(+), 1385 deletions(-) delete mode 100644 docker-compose_enterprise.yml rename src/main/assembly/{enterprise => }/assembly.xml (96%) delete mode 100644 src/main/assembly/enterprise/native-assembly.xml rename src/main/assembly/{standalone => }/native-assembly.xml (96%) delete mode 100644 src/main/assembly/standalone/assembly.xml rename src/main/distribution/config/{enterprise => }/application.properties (62%) delete mode 100644 src/main/distribution/config/standalone/application.properties rename src/{test/java/io/github/project/openubl/searchpe/resources/EnterpriseVersionResourceTest.java => main/java/io/github/project/openubl/searchpe/models/FilterBean.java} (59%) create mode 100644 src/main/java/io/github/project/openubl/searchpe/resources/WhoAmIResource.java create mode 100644 src/main/java/io/github/project/openubl/searchpe/security/DisabledAuthController.java delete mode 100644 src/main/resources/application-enterprise.properties create mode 100644 src/main/webapp/src/queries/whoami.ts delete mode 100644 src/main/webapp/src/shared/components/layout/HeaderApp/BasicMenuDropdownItems.tsx delete mode 100644 src/main/webapp/src/shared/components/layout/HeaderApp/OidcMenuDropdownItems.tsx delete mode 100644 src/main/webapp/src/shared/components/layout/HeaderApp/SSOMenu.tsx create mode 100644 src/main/webapp/src/shared/components/layout/HeaderApp/UserDropdown.tsx rename src/test/java/io/github/project/openubl/searchpe/{EnterpriseProfileManager.java => BasicProfileManager.java} (83%) rename src/test/java/io/github/project/openubl/searchpe/{StandaloneProfileManager.java => DefaultProfileManager.java} (83%) delete mode 100644 src/test/java/io/github/project/openubl/searchpe/FlywayTestCallback.java rename src/test/java/io/github/project/openubl/searchpe/resources/{AbstractContribuyenteResourceTest.java => ContribuyenteResourceTest.java} (85%) rename src/test/java/io/github/project/openubl/searchpe/resources/{EnterpriseSearchContribuyenteResourceTest.java => ContribuyenteSearchResourceTest.java} (96%) rename src/test/java/io/github/project/openubl/searchpe/resources/{StandaloneCurrentUserResourceTest.java => CurrentUserResourceTest.java} (67%) delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseContribuyenteResourceTest.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseCurrentUserResourceTest.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseUserResourceTest.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseContribuyenteResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseCurrentUserResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseVersionResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneContribuyenteResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneCurrentUserResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneVersionResourceIT.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/StandaloneContribuyenteResourceTest.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/StandaloneSearchContribuyenteResourceTest.java delete mode 100644 src/test/java/io/github/project/openubl/searchpe/resources/StandaloneVersionResourceTest.java rename src/test/java/io/github/project/openubl/searchpe/resources/{StandaloneUserResourceTest.java => UserResourceTest.java} (97%) rename src/test/java/io/github/project/openubl/searchpe/resources/{AbstractVersionResourceTest.java => VersionResourceTest.java} (95%) rename src/test/java/io/github/project/openubl/searchpe/resources/{AbstractCurrentUserResourceTest.java => WhoAmIResourceTest.java} (78%) delete mode 100644 src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback delete mode 100644 src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback rename src/test/resources/db/io/github/project/openubl/searchpe/resources/{AbstractContribuyenteResourceTest => ContribuyenteResourceTest}/V9999.0.1__test.sql (100%) rename src/test/resources/db/io/github/project/openubl/searchpe/resources/{AbstractVersionResourceTest => VersionResourceTest}/V9999.0.1__test.sql (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2ffb3551..2beb0211 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,10 +27,6 @@ jobs: native-tests: name: Native Tests runs-on: ubuntu-latest - strategy: - matrix: - flavor: [ "standalone", "enterprise" ] - fail-fast: false steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 @@ -39,7 +35,7 @@ jobs: distribution: temurin cache: maven - name: Build with Maven - run: mvn verify -Dquarkus.native.container-build=true -P native,${{ matrix.flavor }} + run: mvn verify -Dquarkus.native.container-build=true -P native ui-tests: name: UI Tests diff --git a/.github/workflows/pr-build-container-images-comment-boot.yml b/.github/workflows/pr-build-container-images-comment-boot.yml index a9d6f4da..e1df666b 100644 --- a/.github/workflows/pr-build-container-images-comment-boot.yml +++ b/.github/workflows/pr-build-container-images-comment-boot.yml @@ -18,7 +18,6 @@ jobs: The creation of the container image might take aproximately 10 minutes. Once it is available you can pull it using: ```shell docker pull ghcr.io/${{github.event.pull_request.head.repo.full_name}}/${{github.event.repository.name}}:${{github.event.pull_request.head.ref}} - docker pull ghcr.io/${{github.event.pull_request.head.repo.full_name}}/${{github.event.repository.name}}-enterprise:${{github.event.pull_request.head.ref}} ``` - To watch the current status of the container image creation visit [Workflow runs](https://github.com/${{github.event.pull_request.head.repo.full_name}}/actions/workflows/pr-build-container-images.yml?query=branch%3A${{github.event.pull_request.head.ref}}) @@ -65,86 +64,5 @@ jobs: condition: service_healthy ``` - -
- Docker compose - enterprise -
- ```yaml - version: "3" - services: - postgresql: - image: postgres:13.1 - environment: - POSTGRES_DB: searchpe_db - POSTGRES_USER: db_username - POSTGRES_PASSWORD: db_password - network_mode: "host" - healthcheck: - test: [ "CMD-SHELL", "pg_isready -U db_username -d searchpe_db" ] - interval: 10s - timeout: 5s - retries: 5 - - elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2 - environment: - discovery.type: single-node - network_mode: "host" - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:9200" ] - interval: 10s - timeout: 5s - retries: 5 - - keycloak: - image: quay.io/keycloak/keycloak:15.0.2 - environment: - KEYCLOAK_USER: admin - KEYCLOAK_PASSWORD: admin - KEYCLOAK_IMPORT: /tmp/openubl-realm.json - DB_VENDOR: h2 - volumes: - - ./src/main/resources/openubl-realm.json:/tmp/openubl-realm.json:z - command: - - "-Djboss.bind.address.private=127.0.0.1" - - "-Djboss.bind.address=0.0.0.0" - network_mode: "host" - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:8080/auth" ] - interval: 10s - timeout: 5s - retries: 5 - - searchpe: - image: quay.io/projectopenubl/searchpe-enterprise:early-access - environment: - QUARKUS_HTTP_PORT: 8180 - QUARKUS_DATASOURCE_USERNAME: db_username - QUARKUS_DATASOURCE_PASSWORD: db_password - QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://localhost:5432/searchpe_db - QUARKUS_OIDC_ENABLED: "true" - QUARKUS_OIDC_AUTH_SERVER_URL: http://localhost:8080/auth/realms/openubl - QUARKUS_OIDC_CLIENT_ID: searchpe - QUARKUS_OIDC_CREDENTIALS_SECRET: secret - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_USERNAME: any - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PASSWORD: any - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PROTOCOL: HTTP - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_HOSTS: localhost:9200 - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_VERSION: 7 - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:8080/q/health" ] - interval: 10s - timeout: 5s - retries: 5 - network_mode: "host" - depends_on: - postgresql: - condition: service_healthy - elasticsearch: - condition: service_healthy - keycloak: - condition: service_healthy - ``` -
repo-token: ${{ steps.token.outputs.GH_TOKEN }} diff --git a/.github/workflows/pr-build-container-images.yml b/.github/workflows/pr-build-container-images.yml index 2b962026..9328fde9 100644 --- a/.github/workflows/pr-build-container-images.yml +++ b/.github/workflows/pr-build-container-images.yml @@ -6,10 +6,6 @@ jobs: container-images: if: ${{ github.event_name != 'pull_request' && github.repository_owner != 'project-openubl' }} runs-on: ubuntu-latest - strategy: - matrix: - flavor: [ "standalone", "enterprise" ] - fail-fast: false steps: - uses: actions/checkout@v3 - uses: actions/setup-java@v3 @@ -18,18 +14,6 @@ jobs: distribution: temurin cache: maven - - name: Extract image name - shell: bash - run: | - bash -c ' - flavor=${{ matrix.flavor }}; - image_name="searchpe"; - if [ $flavor != "standalone" ]; then - image_name="$image_name-$flavor" - fi - echo $image_name; - echo "##[set-output name=searchpe_image_name;]$(echo $image_name)"' - id: extract_image_name - name: Extract branch name shell: bash run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" @@ -43,7 +27,7 @@ jobs: -Dquarkus.container-image.build=true \ -Dquarkus.container-image.registry=ghcr.io \ -Dquarkus.container-image.group=${{ github.repository_owner }} \ - -Dquarkus.container-image.name=${{ github.event.repository.name }}/${{ steps.extract_image_name.outputs.searchpe_image_name }} \ + -Dquarkus.container-image.name=${{ github.event.repository.name }}/searchpe \ -Dquarkus.container-image.tag=${{ steps.extract_branch.outputs.branch }} \ -Dquarkus.container-image.username=${{ github.actor }} \ -Dquarkus.container-image.password=${{ secrets.GITHUB_TOKEN }} \ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 14f1ad0d..888f5e85 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -53,10 +53,6 @@ jobs: build-jvm: needs: [ version ] name: Build JVM - strategy: - fail-fast: true - matrix: - flavor: [ "standalone", "enterprise" ] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v3 @@ -79,7 +75,7 @@ jobs: cache: maven - name: Build and Create distribution - run: mvn -B --file pom.xml package -DskipTests -P ui,distribution-${{ matrix.flavor }} + run: mvn -B --file pom.xml package -DskipTests -P ui,distribution - name: Upload build artifact uses: actions/upload-artifact@v3 with: @@ -91,10 +87,6 @@ jobs: build-container: needs: [ version ] name: Build Container - strategy: - fail-fast: true - matrix: - flavor: [ "standalone", "enterprise" ] runs-on: ubuntu-latest steps: - uses: actions/download-artifact@v3 @@ -124,16 +116,16 @@ jobs: -Dquarkus.container-image.build=true \ -Dquarkus.container-image.registry=quay.io \ -Dquarkus.container-image.group=projectopenubl \ - -Dquarkus.container-image.name=searchpe-${{ matrix.flavor }} \ + -Dquarkus.container-image.name=searchpe \ -Dquarkus.container-image.tag=latest \ - -P native,ui,${{ matrix.flavor }} + -P native,ui - name: Save container image - run: docker save -o searchpe-${{ matrix.flavor }}-container-image.tar quay.io/projectopenubl/searchpe-${{ matrix.flavor }}:latest + run: docker save -o searchpe-container-image.tar quay.io/projectopenubl/searchpe:latest - name: Upload container image uses: actions/upload-artifact@v3 with: name: artifacts - path: searchpe-${{ matrix.flavor }}-container-image.tar + path: searchpe-container-image.tar release: needs: [ build-jvm, build-container ] @@ -171,14 +163,11 @@ jobs: - name: Load and config images run: | # Load images from .tar - docker load -i artifacts/searchpe-standalone-container-image.tar - docker load -i artifacts/searchpe-enterprise-container-image.tar + docker load -i artifacts/searchpe-container-image.tar # Tag images - docker tag quay.io/projectopenubl/searchpe-standalone:latest quay.io/projectopenubl/searchpe:latest - docker tag quay.io/projectopenubl/searchpe-standalone:latest quay.io/projectopenubl/searchpe:${{ steps.version.outputs.RELEASE_VERSION }} - docker tag quay.io/projectopenubl/searchpe-enterprise:latest quay.io/projectopenubl/searchpe-standalone:${{ steps.version.outputs.RELEASE_VERSION }} - docker tag quay.io/projectopenubl/searchpe-enterprise:latest quay.io/projectopenubl/searchpe-enterprise:${{ steps.version.outputs.RELEASE_VERSION }} + docker tag quay.io/projectopenubl/searchpe:latest quay.io/projectopenubl/searchpe:latest + docker tag quay.io/projectopenubl/searchpe:latest quay.io/projectopenubl/searchpe:${{ steps.version.outputs.RELEASE_VERSION }} - name: Login to Quay.io uses: docker/login-action@v1 @@ -191,12 +180,6 @@ jobs: run: | docker push quay.io/projectopenubl/searchpe:latest docker push quay.io/projectopenubl/searchpe:v${{ steps.version.outputs.RELEASE_VERSION }} - - docker push quay.io/projectopenubl/searchpe-standalone:latest - docker push quay.io/projectopenubl/searchpe-standalone:v${{ steps.version.outputs.RELEASE_VERSION }} - - docker push quay.io/projectopenubl/searchpe-enterprise:latest - docker push quay.io/projectopenubl/searchpe-enterprise:v${{ steps.version.outputs.RELEASE_VERSION }} - name: Release with JReleaser uses: jreleaser/release-action@v1 diff --git a/.github/workflows/snapshots.yml b/.github/workflows/snapshots.yml index bc90ec07..49e18bea 100644 --- a/.github/workflows/snapshots.yml +++ b/.github/workflows/snapshots.yml @@ -22,14 +22,11 @@ jobs: distribution: temurin cache: maven - name: Maven - run: mvn test -Pstandalone -Dtest=DataHelperTest -Dsearchpe.sunat.padronReducidoUrl=http://www2.sunat.gob.pe/padron_reducido_ruc.zip + run: mvn test -Dtest=DataHelperTest -Dsearchpe.sunat.padronReducidoUrl=http://www2.sunat.gob.pe/padron_reducido_ruc.zip build-snapshot-container: needs: [ linux-jvm-tests ] name: Build Container - strategy: - matrix: - flavor: [ "standalone", "enterprise" ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -46,16 +43,16 @@ jobs: -Dquarkus.container-image.build=true \ -Dquarkus.container-image.registry=quay.io \ -Dquarkus.container-image.group=projectopenubl \ - -Dquarkus.container-image.name=searchpe-${{ matrix.flavor }} \ + -Dquarkus.container-image.name=searchpe \ -Dquarkus.container-image.tag=latest \ - -P native,ui,${{ matrix.flavor }} + -P native,ui - name: Save container image - run: docker save -o searchpe-${{ matrix.flavor }}-container-image.tar quay.io/projectopenubl/searchpe-${{ matrix.flavor }}:latest + run: docker save -o searchpe-container-image.tar quay.io/projectopenubl/searchpe:latest - name: Upload container image uses: actions/upload-artifact@v3 with: name: artifacts - path: searchpe-${{ matrix.flavor }}-container-image.tar + path: searchpe-container-image.tar snapshots: needs: [ build-snapshot-container ] @@ -78,24 +75,12 @@ jobs: - name: Load and config images run: | # Load images from .tar - docker load -i artifacts/searchpe-standalone-container-image.tar - docker load -i artifacts/searchpe-enterprise-container-image.tar + docker load -i artifacts/searchpe-container-image.tar # Tag images - docker tag quay.io/projectopenubl/searchpe-standalone:latest quay.io/projectopenubl/searchpe:early-access - docker tag quay.io/projectopenubl/searchpe-enterprise:latest quay.io/projectopenubl/searchpe-standalone:early-access - docker tag quay.io/projectopenubl/searchpe-enterprise:latest quay.io/projectopenubl/searchpe-enterprise:early-access - - docker tag quay.io/projectopenubl/searchpe-standalone:latest ghcr.io/project-openubl/searchpe/searchpe:early-access - docker tag quay.io/projectopenubl/searchpe-enterprise:latest ghcr.io/project-openubl/searchpe/searchpe-standalone:early-access - docker tag quay.io/projectopenubl/searchpe-enterprise:latest ghcr.io/project-openubl/searchpe/searchpe-enterprise:early-access + docker tag quay.io/projectopenubl/searchpe:latest quay.io/projectopenubl/searchpe:early-access + docker tag quay.io/projectopenubl/searchpe:latest ghcr.io/project-openubl/searchpe/searchpe:early-access - name: Push images to registry run: | - docker push quay.io/projectopenubl/searchpe:early-access - docker push quay.io/projectopenubl/searchpe-standalone:early-access - docker push quay.io/projectopenubl/searchpe-enterprise:early-access - - docker push ghcr.io/project-openubl/searchpe/searchpe:early-access - docker push ghcr.io/project-openubl/searchpe/searchpe-standalone:early-access - docker push ghcr.io/project-openubl/searchpe/searchpe-enterprise:early-access - + docker push quay.io/projectopenubl/searchpe:early-access + docker push ghcr.io/project-openubl/searchpe/searchpe:early-access diff --git a/docker-compose.yml b/docker-compose.yml index 54a98dab..a0b6ac7a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -32,20 +32,62 @@ services: timeout: 5s retries: 5 + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:7.17.0 + environment: + discovery.type: single-node + network_mode: "host" + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:9200" ] + interval: 10s + timeout: 5s + retries: 5 + + keycloak: + image: quay.io/keycloak/keycloak:15.0.2 + environment: + KEYCLOAK_USER: admin + KEYCLOAK_PASSWORD: admin + KEYCLOAK_IMPORT: /tmp/openubl-realm.json + DB_VENDOR: h2 + volumes: + - ./src/main/resources/openubl-realm.json:/tmp/openubl-realm.json:z + command: + - "-Djboss.bind.address.private=127.0.0.1" + - "-Djboss.bind.address=0.0.0.0" + network_mode: "host" + healthcheck: + test: [ "CMD", "curl", "-f", "http://localhost:8080/auth" ] + interval: 10s + timeout: 5s + retries: 5 + searchpe: - image: quay.io/projectopenubl/searchpe:early-access - ports: - - 8180:8080 + image: quay.io/projectopenubl/searchpe:latest environment: - QUARKUS_HTTP_PORT: 8080 + QUARKUS_HTTP_PORT: 8180 QUARKUS_DATASOURCE_USERNAME: db_username QUARKUS_DATASOURCE_PASSWORD: db_password - QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://postgresql:5432/searchpe_db + QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://localhost:5432/searchpe_db + QUARKUS_OIDC_AUTH_SERVER_URL: http://localhost:8080/auth/realms/openubl + QUARKUS_OIDC_CLIENT_ID: searchpe + QUARKUS_OIDC_CREDENTIALS_SECRET: secret + QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_USERNAME: any + QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PASSWORD: any + QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PROTOCOL: HTTP + QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_HOSTS: localhost:9200 + QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_VERSION: 7 + QUARKUS_PROFILE: "prod" healthcheck: test: [ "CMD", "curl", "-f", "http://localhost:8080/q/health" ] interval: 10s timeout: 5s retries: 5 + network_mode: "host" depends_on: postgresql: condition: service_healthy + keycloak: + condition: service_healthy + elasticsearch: + condition: service_healthy diff --git a/docker-compose_enterprise.yml b/docker-compose_enterprise.yml deleted file mode 100644 index 487fc711..00000000 --- a/docker-compose_enterprise.yml +++ /dev/null @@ -1,92 +0,0 @@ -# -# Copyright 2019 Project OpenUBL, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# 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. -# - -version: "3" - -services: - postgresql: - image: postgres:13.1 - environment: - POSTGRES_DB: searchpe_db - POSTGRES_USER: db_username - POSTGRES_PASSWORD: db_password - network_mode: "host" - healthcheck: - test: [ "CMD-SHELL", "pg_isready -U db_username -d searchpe_db" ] - interval: 10s - timeout: 5s - retries: 5 - - elasticsearch: - image: docker.elastic.co/elasticsearch/elasticsearch:7.10.2 - environment: - discovery.type: single-node - network_mode: "host" - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:9200" ] - interval: 10s - timeout: 5s - retries: 5 - - keycloak: - image: quay.io/keycloak/keycloak:15.0.2 - environment: - KEYCLOAK_USER: admin - KEYCLOAK_PASSWORD: admin - KEYCLOAK_IMPORT: /tmp/openubl-realm.json - DB_VENDOR: h2 - volumes: - - ./src/main/resources/openubl-realm.json:/tmp/openubl-realm.json:z - command: - - "-Djboss.bind.address.private=127.0.0.1" - - "-Djboss.bind.address=0.0.0.0" - network_mode: "host" - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:8080/auth" ] - interval: 10s - timeout: 5s - retries: 5 - - searchpe: - image: quay.io/projectopenubl/searchpe-enterprise:early-access - environment: - QUARKUS_HTTP_PORT: 8180 - QUARKUS_DATASOURCE_USERNAME: db_username - QUARKUS_DATASOURCE_PASSWORD: db_password - QUARKUS_DATASOURCE_JDBC_URL: jdbc:postgresql://localhost:5432/searchpe_db - QUARKUS_OIDC_ENABLED: "true" - QUARKUS_OIDC_AUTH_SERVER_URL: http://localhost:8080/auth/realms/openubl - QUARKUS_OIDC_CLIENT_ID: searchpe - QUARKUS_OIDC_CREDENTIALS_SECRET: secret - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_USERNAME: any - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PASSWORD: any - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_PROTOCOL: HTTP - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_HOSTS: localhost:9200 - QUARKUS_HIBERNATE_SEARCH_ORM_ELASTICSEARCH_VERSION: 7 - healthcheck: - test: [ "CMD", "curl", "-f", "http://localhost:8080/q/health" ] - interval: 10s - timeout: 5s - retries: 5 - network_mode: "host" - depends_on: - postgresql: - condition: service_healthy - elasticsearch: - condition: service_healthy - keycloak: - condition: service_healthy diff --git a/jreleaser.yml b/jreleaser.yml index 1dc627d9..67bb8045 100644 --- a/jreleaser.yml +++ b/jreleaser.yml @@ -13,14 +13,10 @@ project: inceptionYear: 2019 distributions: - standalone-jvm: + jvm: artifacts: - path: artifacts/searchpe-{{projectVersion}}-jvm.tar.gz - path: artifacts/searchpe-{{projectVersion}}-jvm.zip - enterprise-jvm: - artifacts: - - path: artifacts/searchpe-enterprise-{{projectVersion}}-jvm.tar.gz - - path: artifacts/searchpe-enterprise-{{projectVersion}}-jvm.zip release: github: diff --git a/pom.xml b/pom.xml index f49c80d3..0ffd2070 100644 --- a/pom.xml +++ b/pom.xml @@ -165,6 +165,10 @@ io.quarkus quarkus-oidc + + io.quarkus + quarkus-security + io.quarkus @@ -453,7 +457,7 @@ - distribution-standalone + distribution @@ -462,7 +466,7 @@ ${maven-assembly-plugin.version} - standalone-distribution + distribution package single @@ -475,39 +479,7 @@ ${project.build.directory}/assembly/work false - src/main/assembly/standalone/assembly.xml - - - - - - - - - - distribution-enterprise - - - - org.apache.maven.plugins - maven-assembly-plugin - ${maven-assembly-plugin.version} - - - enterprise-distribution - package - - single - - - false - false - ${project.artifactId}-enterprise-${project.version}-jvm - ${project.build.directory}/distributions - ${project.build.directory}/assembly/work - false - - src/main/assembly/enterprise/assembly.xml + src/main/assembly/assembly.xml diff --git a/src/main/assembly/enterprise/assembly.xml b/src/main/assembly/assembly.xml similarity index 96% rename from src/main/assembly/enterprise/assembly.xml rename to src/main/assembly/assembly.xml index 7636f410..1652be5e 100644 --- a/src/main/assembly/enterprise/assembly.xml +++ b/src/main/assembly/assembly.xml @@ -51,7 +51,7 @@ false - src/main/distribution/config/enterprise + src/main/distribution/config ./config false diff --git a/src/main/assembly/enterprise/native-assembly.xml b/src/main/assembly/enterprise/native-assembly.xml deleted file mode 100644 index 5c3156e1..00000000 --- a/src/main/assembly/enterprise/native-assembly.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - - native-distribution - - tar.gz - zip - dir - - - - - LICENSE - ./ - - - src/main/distribution/README - ./ - - - ${project.build.directory}/${project.artifactId}-${project.version}-runner${executable-suffix} - ./bin - ${project.artifactId}${executable-suffix} - 0755 - - - - - - src/main/distribution/bin - ./bin - false - - - src/main/distribution/config/enterprise - ./config - false - - - diff --git a/src/main/assembly/standalone/native-assembly.xml b/src/main/assembly/native-assembly.xml similarity index 96% rename from src/main/assembly/standalone/native-assembly.xml rename to src/main/assembly/native-assembly.xml index 33992202..f9a4454e 100644 --- a/src/main/assembly/standalone/native-assembly.xml +++ b/src/main/assembly/native-assembly.xml @@ -51,7 +51,7 @@ false - src/main/distribution/config/standalone + src/main/distribution/config ./config false diff --git a/src/main/assembly/standalone/assembly.xml b/src/main/assembly/standalone/assembly.xml deleted file mode 100644 index c7a11646..00000000 --- a/src/main/assembly/standalone/assembly.xml +++ /dev/null @@ -1,60 +0,0 @@ - - - - distribution - - tar.gz - zip - dir - - - ${project.build.finalName} - - - - LICENSE - ./ - - - src/main/distribution/README - ./ - - - - - - - ${project.build.directory}/quarkus-app - ./ - - - src/main/distribution/bin - ./bin - false - - - src/main/distribution/config/standalone - ./config - false - - - - diff --git a/src/main/distribution/config/enterprise/application.properties b/src/main/distribution/config/application.properties similarity index 62% rename from src/main/distribution/config/enterprise/application.properties rename to src/main/distribution/config/application.properties index 457b6f9d..1e5a2429 100644 --- a/src/main/distribution/config/enterprise/application.properties +++ b/src/main/distribution/config/application.properties @@ -31,17 +31,17 @@ searchpe.scheduled.cron=0 0 0 * * ? searchpe.scheduled.cron-clean=0 0 6 * * ? # Oidc Auth -quarkus.oidc.enabled=true -quarkus.oidc.client-id=searchpe -quarkus.oidc.credentials.secret=secret -quarkus.oidc.auth-server-url=http://localhost:8080/auth/realms/openubl +#quarkus.oidc.enabled=true +#quarkus.oidc.client-id=searchpe +#quarkus.oidc.credentials.secret=secret +#quarkus.oidc.auth-server-url=http://localhost:8080/auth/realms/openubl # Elasticsearch -quarkus.hibernate-search-orm.elasticsearch.username=es_username -quarkus.hibernate-search-orm.elasticsearch.password=es_password -quarkus.hibernate-search-orm.elasticsearch.hosts=localhost:9200 -quarkus.hibernate-search-orm.elasticsearch.protocol=HTTP -quarkus.hibernate-search-orm.elasticsearch.version=7 -quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true -quarkus.hibernate-search-orm.schema-management.strategy=CREATE_OR_VALIDATE -quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=write-sync +#quarkus.hibernate-search-orm.elasticsearch.username=es_username +#quarkus.hibernate-search-orm.elasticsearch.password=es_password +#quarkus.hibernate-search-orm.elasticsearch.hosts=localhost:9200 +#quarkus.hibernate-search-orm.elasticsearch.protocol=HTTP +#quarkus.hibernate-search-orm.elasticsearch.version=7 +#quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true +#quarkus.hibernate-search-orm.schema-management.strategy=CREATE_OR_VALIDATE +#quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=write-sync diff --git a/src/main/distribution/config/standalone/application.properties b/src/main/distribution/config/standalone/application.properties deleted file mode 100644 index 114180ab..00000000 --- a/src/main/distribution/config/standalone/application.properties +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright 2019 Project OpenUBL, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# 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. -# - -# Quarkus settings -quarkus.http.port=8180 - -# PostgreSQL settings -quarkus.datasource.username=db_username -quarkus.datasource.password=db_password -quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5432/searchpe_db - -# SUNAT settings -searchpe.sunat.padronReducidoUrl=http://www2.sunat.gob.pe/padron_reducido_ruc.zip -searchpe.sunat.filter=ACTIVO -searchpe.workspace.directory=searchpe/workspace -searchpe.scheduled.cron=0 0 0 * * ? -searchpe.scheduled.cron-clean=0 0 6 * * ? diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseVersionResourceTest.java b/src/main/java/io/github/project/openubl/searchpe/models/FilterBean.java similarity index 59% rename from src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseVersionResourceTest.java rename to src/main/java/io/github/project/openubl/searchpe/models/FilterBean.java index 19eea57b..5436483c 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseVersionResourceTest.java +++ b/src/main/java/io/github/project/openubl/searchpe/models/FilterBean.java @@ -14,14 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.github.project.openubl.searchpe.resources; +package io.github.project.openubl.searchpe.models; -import io.github.project.openubl.searchpe.EnterpriseProfileManager; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; +public class FilterBean { -@QuarkusTest -@TestProfile(EnterpriseProfileManager.class) -public class EnterpriseVersionResourceTest extends AbstractVersionResourceTest { + private String filterText; + private String tipoPersona; + public String getFilterText() { + return filterText; + } + + public void setFilterText(String filterText) { + this.filterText = filterText; + } + + public String getTipoPersona() { + return tipoPersona; + } + + public void setTipoPersona(String tipoPersona) { + this.tipoPersona = tipoPersona; + } } diff --git a/src/main/java/io/github/project/openubl/searchpe/models/jpa/ContribuyenteRepository.java b/src/main/java/io/github/project/openubl/searchpe/models/jpa/ContribuyenteRepository.java index 8c0f371b..0d073564 100644 --- a/src/main/java/io/github/project/openubl/searchpe/models/jpa/ContribuyenteRepository.java +++ b/src/main/java/io/github/project/openubl/searchpe/models/jpa/ContribuyenteRepository.java @@ -16,9 +16,11 @@ */ package io.github.project.openubl.searchpe.models.jpa; +import io.github.project.openubl.searchpe.models.FilterBean; import io.github.project.openubl.searchpe.models.PageBean; import io.github.project.openubl.searchpe.models.PageModel; import io.github.project.openubl.searchpe.models.SortBean; +import io.github.project.openubl.searchpe.models.TipoPersona; import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteEntity; import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteId; import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity; @@ -26,10 +28,22 @@ import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; import io.quarkus.panache.common.Parameters; import io.quarkus.panache.common.Sort; +import org.hibernate.search.engine.search.predicate.dsl.BooleanPredicateClausesStep; +import org.hibernate.search.engine.search.query.SearchResult; +import org.hibernate.search.engine.search.query.dsl.SearchQueryOptionsStep; +import org.hibernate.search.engine.search.sort.SearchSort; +import org.hibernate.search.engine.search.sort.dsl.CompositeSortComponentsStep; +import org.hibernate.search.engine.search.sort.dsl.SortOrder; +import org.hibernate.search.mapper.orm.scope.SearchScope; +import org.hibernate.search.mapper.orm.search.loading.dsl.SearchLoadingOptionsStep; +import org.hibernate.search.mapper.orm.session.SearchSession; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; import javax.transaction.Transactional; import java.util.List; +import java.util.Optional; @Transactional @ApplicationScoped @@ -37,33 +51,34 @@ public class ContribuyenteRepository implements PanacheRepositoryBase list(VersionEntity version, PageBean pageBean, List sortBy) { - Sort sort = Sort.by(); - sortBy.forEach(f -> sort.and(f.getFieldName(), f.isAsc() ? Sort.Direction.Ascending : Sort.Direction.Descending)); - - PanacheQuery query = VersionEntity - .find( - "From ContribuyenteEntity as c where c.id.versionId =:versionId", - sort, - Parameters.with("versionId", version.id) - ) - .range(pageBean.getOffset(), pageBean.getOffset() + pageBean.getLimit() - 1); + @Inject + Instance searchSession; - long count = query.count(); - List list = query.list(); - return new PageModel<>(pageBean, count, list); + private Optional getSearchSession() { + for (SearchSession session : searchSession) { + return Optional.of(session); + } + return Optional.empty(); } - public PageModel list(VersionEntity version, String filterText, PageBean pageBean, List sortBy) { + public PageModel list(VersionEntity version, FilterBean filterBean, PageBean pageBean, List sortBy) { Sort sort = Sort.by(); sortBy.forEach(f -> sort.and(f.getFieldName(), f.isAsc() ? Sort.Direction.Ascending : Sort.Direction.Descending)); + StringBuilder queryBuilder = new StringBuilder("From ContribuyenteEntity as c where c.id.versionId =:versionId"); + Parameters parameters = Parameters.with("versionId", version.id); + + if (filterBean.getFilterText() != null) { + queryBuilder.append(" and lower(c.nombre) like :filterText"); + parameters.and("filterText", "%" + filterBean.getFilterText().toLowerCase() + "%"); + } + if (filterBean.getTipoPersona() != null) { + queryBuilder.append(" and c.tipoPersona = :tipoPersona"); + parameters.and("tipoPersona", TipoPersona.valueOf(filterBean.getTipoPersona().trim().toUpperCase())); + } + PanacheQuery query = VersionEntity - .find( - "From ContribuyenteEntity as c where c.id.versionId =:versionId and c.nombre like :filterText", - sort, - Parameters.with("versionId", version.id).and("filterText", "%" + filterText.toUpperCase()) - ) + .find(queryBuilder.toString(), sort, parameters) .range(pageBean.getOffset(), pageBean.getOffset() + pageBean.getLimit() - 1); long count = query.count(); @@ -71,4 +86,42 @@ public PageModel list(VersionEntity version, String filterT return new PageModel<>(pageBean, count, list); } + public PageModel listES(VersionEntity version, FilterBean filterBean, PageBean pageBean, List sortBy) { + SearchSession searchSession = getSearchSession().orElseThrow(() -> new IllegalStateException("Could not find a SearchSession available")); + SearchSort searchSort = null; + if (!sortBy.isEmpty()) { + SearchScope searchScope = searchSession.scope(ContribuyenteEntity.class); + + CompositeSortComponentsStep compositeSortComponents = searchScope.sort().composite(); + sortBy.stream() + .map(f -> searchScope.sort() + .field(f.getFieldName() + "_sort") + .order(f.isAsc() ? SortOrder.ASC : SortOrder.DESC) + .toSort()) + .forEach(compositeSortComponents::add); + + searchSort = compositeSortComponents.toSort(); + } + + SearchQueryOptionsStep searchQuery = searchSession.search(ContribuyenteEntity.class) + .where(f -> { + BooleanPredicateClausesStep result = f.bool(); + result = result.must(f.match().field("embeddedId.versionId").matching(version.id)); + if (filterBean.getFilterText() != null && !filterBean.getFilterText().trim().isEmpty()) { + result = result.must(f.match().fields("nombre").matching(filterBean.getFilterText())); + } + if (filterBean.getTipoPersona() != null && !filterBean.getTipoPersona().trim().isEmpty()) { + TipoPersona tipoContribuyente = TipoPersona.valueOf(filterBean.getTipoPersona().trim().toUpperCase()); + result = result.must(f.match().field("tipoPersona").matching(tipoContribuyente)); + } + return result; + }); + + if (searchSort != null) { + searchQuery = searchQuery.sort(searchSort); + } + SearchResult searchResult = searchQuery.fetch(pageBean.getOffset(), pageBean.getLimit()); + + return new PageModel<>(pageBean, searchResult.total().hitCount(), searchResult.hits()); + } } diff --git a/src/main/java/io/github/project/openubl/searchpe/resources/ContribuyenteResource.java b/src/main/java/io/github/project/openubl/searchpe/resources/ContribuyenteResource.java index 30d68137..5354e4a6 100644 --- a/src/main/java/io/github/project/openubl/searchpe/resources/ContribuyenteResource.java +++ b/src/main/java/io/github/project/openubl/searchpe/resources/ContribuyenteResource.java @@ -16,7 +16,9 @@ */ package io.github.project.openubl.searchpe.resources; +import io.github.project.openubl.searchpe.models.FilterBean; import io.github.project.openubl.searchpe.models.PageBean; +import io.github.project.openubl.searchpe.models.PageModel; import io.github.project.openubl.searchpe.models.PageRepresentation; import io.github.project.openubl.searchpe.models.SortBean; import io.github.project.openubl.searchpe.models.TipoPersona; @@ -26,6 +28,7 @@ import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteId; import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity; import io.github.project.openubl.searchpe.security.Permission; +import io.github.project.openubl.searchpe.utils.EntityToRepresentation; import io.github.project.openubl.searchpe.utils.ResourceUtils; import org.eclipse.microprofile.config.inject.ConfigProperty; import org.eclipse.microprofile.metrics.annotation.Counted; @@ -47,7 +50,13 @@ import javax.inject.Inject; import javax.transaction.Transactional; import javax.validation.constraints.Max; -import javax.ws.rs.*; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -66,16 +75,6 @@ public class ContribuyenteResource { @Inject ContribuyenteRepository contribuyenteRepository; - @Inject - Instance searchSession; - - private Optional getSearchSession() { - for (SearchSession session : searchSession) { - return Optional.of(session); - } - return Optional.empty(); - } - @RolesAllowed({Permission.admin, Permission.search}) @Operation(summary = "Search contribuyentes", description = "Get contribuyentes in a page") @GET @@ -85,17 +84,11 @@ private Optional getSearchSession() { @Timed(name = "searchContribuyenteTimer", description = "How long it took to serve the advanced search") public PageRepresentation getContribuyentes( @QueryParam("filterText") String filterText, - @QueryParam("tipoContribuyente") String tipoContribuyenteQuery, + @QueryParam("tipoContribuyente") String tipoPersona, @QueryParam("offset") @DefaultValue("0") @Max(9_000) Integer offset, @QueryParam("limit") @DefaultValue("10") @Max(1_000) Integer limit, @QueryParam("sort_by") @DefaultValue("name") List sortBy ) { - if (isESEnabled.isEmpty() || !isESEnabled.get()) { - throw new NotFoundException(); - } - - SearchSession searchSession = getSearchSession().orElseThrow(() -> new IllegalStateException("Could not find a SearchSession available")); - Optional versionOptional = versionRepository.findActive(); if (versionOptional.isEmpty()) { PageRepresentation result = new PageRepresentation<>(); @@ -115,50 +108,17 @@ public PageRepresentation getContribuyentes( PageBean pageBean = ResourceUtils.getPageBean(offset, limit); List sortBeans = ResourceUtils.getSortBeans(sortBy, ContribuyenteRepository.SORT_BY_FIELDS); - SearchSort searchSort = null; - if (!sortBeans.isEmpty()) { - SearchScope searchScope = searchSession.scope(ContribuyenteEntity.class); + FilterBean filterBean = new FilterBean(); + filterBean.setFilterText(filterText); + filterBean.setTipoPersona(tipoPersona); - CompositeSortComponentsStep compositeSortComponents = searchScope.sort().composite(); - sortBeans.stream() - .map(f -> searchScope.sort() - .field(f.getFieldName() + "_sort") - .order(f.isAsc() ? SortOrder.ASC : SortOrder.DESC) - .toSort()) - .forEach(compositeSortComponents::add); - - searchSort = compositeSortComponents.toSort(); - } - - SearchQueryOptionsStep searchQuery = searchSession.search(ContribuyenteEntity.class) - .where(f -> { - BooleanPredicateClausesStep result = f.bool(); - result = result.must(f.match().field("embeddedId.versionId").matching(version.id)); - if (filterText != null && !filterText.trim().isEmpty()) { - result = result.must(f.match().fields("nombre").matching(filterText)); - } - if (tipoContribuyenteQuery != null && !tipoContribuyenteQuery.trim().isEmpty()) { - TipoPersona tipoContribuyente = TipoPersona.valueOf(tipoContribuyenteQuery.trim().toUpperCase()); - result = result.must(f.match().field("tipoPersona").matching(tipoContribuyente)); - } - return result; - }); - - if (searchSort != null) { - searchQuery = searchQuery.sort(searchSort); + PageModel list; + if (!isESEnabled.orElse(false)) { + list = contribuyenteRepository.list(version, filterBean, pageBean, sortBeans); + } else { + list = contribuyenteRepository.listES(version, filterBean, pageBean, sortBeans); } - SearchResult searchResult = searchQuery.fetch(offset, limit); - - PageRepresentation.Meta meta = new PageRepresentation.Meta(); - meta.setOffset(pageBean.getOffset()); - meta.setLimit(pageBean.getLimit()); - meta.setCount(searchResult.total().hitCount()); - - PageRepresentation result = new PageRepresentation<>(); - result.setMeta(meta); - result.setData(searchResult.hits()); - - return result; + return EntityToRepresentation.toRepresentation(list, entity -> entity); } @RolesAllowed({Permission.admin, Permission.search}) diff --git a/src/main/java/io/github/project/openubl/searchpe/resources/CurrentUserResource.java b/src/main/java/io/github/project/openubl/searchpe/resources/CurrentUserResource.java index 1fd4366d..66b3722a 100644 --- a/src/main/java/io/github/project/openubl/searchpe/resources/CurrentUserResource.java +++ b/src/main/java/io/github/project/openubl/searchpe/resources/CurrentUserResource.java @@ -20,29 +20,19 @@ import io.github.project.openubl.searchpe.idm.BasicUserRepresentation; import io.github.project.openubl.searchpe.models.jpa.entity.BasicUserEntity; import io.github.project.openubl.searchpe.resources.interceptors.HTTPBasicAuthEnabled; -import io.quarkus.elytron.security.common.BcryptUtil; -import io.quarkus.hibernate.orm.panache.PanacheEntityBase; -import io.quarkus.hibernate.orm.panache.PanacheQuery; import io.quarkus.security.Authenticated; import io.quarkus.security.identity.SecurityIdentity; -import org.eclipse.microprofile.metrics.annotation.Counted; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.transaction.Transactional; -import javax.validation.ConstraintViolation; import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.NotFoundException; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; import java.security.Principal; -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.stream.Collectors; @ApplicationScoped @Consumes("application/json") @@ -53,30 +43,6 @@ public class CurrentUserResource { @Inject SecurityIdentity securityIdentity; - @Authenticated - @GET - @Path("/whoami") - @Counted(name = "getCurrentUserChecks", description = "How many times the current user data was requested") - public BasicUserRepresentation getCurrentUser() { - Principal principal = securityIdentity.getPrincipal(); - - String username = principal.getName(); - Set roles = securityIdentity.getRoles(); - - // Generate result - BasicUserRepresentation result = new BasicUserRepresentation(); - result.setUsername(username); - result.setPermissions(roles.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new))); - - BasicUserEntity.find("username", username).firstResultOptional() - .ifPresent(entity -> { - result.setId(entity.id); - result.setFullName(entity.fullName); - }); - - return result; - } - @Transactional @Authenticated @HTTPBasicAuthEnabled diff --git a/src/main/java/io/github/project/openubl/searchpe/resources/FrontendResource.java b/src/main/java/io/github/project/openubl/searchpe/resources/FrontendResource.java index 5a87f255..ae1adc74 100644 --- a/src/main/java/io/github/project/openubl/searchpe/resources/FrontendResource.java +++ b/src/main/java/io/github/project/openubl/searchpe/resources/FrontendResource.java @@ -26,7 +26,6 @@ import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import java.util.Objects; import java.util.Optional; @Path("/templates") @@ -36,8 +35,11 @@ public class FrontendResource { @Location("settings.js") Template settingsJS; - @ConfigProperty(name = "quarkus.oidc.enabled") - Optional isOidcEnabled; + @ConfigProperty(name = "searchpe.disable.authorization") + Optional disableAuthorization; + + @ConfigProperty(name = "quarkus.oidc.tenant-enabled") + Optional isOidcTenantEnabled; @ConfigProperty(name = "quarkus.hibernate-search-orm.enabled") Optional isESEnabled; @@ -53,8 +55,17 @@ public class FrontendResource { @Path("/settings.js") @Produces("text/javascript") public TemplateInstance getSettingsJS() { + String defaultAuthMethod; + if (disableAuthorization.orElse(false)) { + defaultAuthMethod = "none"; + } else if (isOidcTenantEnabled.orElse(false)) { + defaultAuthMethod = "oidc"; + } else { + defaultAuthMethod = "basic"; + } + return settingsJS - .data("defaultAuthMethod", isOidcEnabled.isPresent() && isOidcEnabled.get() ? "oidc" : "basic") + .data("defaultAuthMethod", defaultAuthMethod) .data("formCookieName", formCookieName.orElse("")) .data("oidcLogoutPath", oidcLogoutPath.orElse("")) .data("isElasticsearchEnabled", isESEnabled.isPresent() && isESEnabled.get()); diff --git a/src/main/java/io/github/project/openubl/searchpe/resources/WhoAmIResource.java b/src/main/java/io/github/project/openubl/searchpe/resources/WhoAmIResource.java new file mode 100644 index 00000000..4cf7f4b1 --- /dev/null +++ b/src/main/java/io/github/project/openubl/searchpe/resources/WhoAmIResource.java @@ -0,0 +1,73 @@ +/* + * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * 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. + */ +package io.github.project.openubl.searchpe.resources; + +import io.github.project.openubl.searchpe.idm.BasicUserRepresentation; +import io.github.project.openubl.searchpe.models.jpa.entity.BasicUserEntity; +import io.quarkus.security.Authenticated; +import io.quarkus.security.identity.SecurityIdentity; +import org.eclipse.microprofile.metrics.annotation.Counted; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.SecurityContext; +import java.security.Principal; +import java.util.LinkedHashSet; +import java.util.Set; +import java.util.stream.Collectors; + +@ApplicationScoped +@Consumes("application/json") +@Produces("application/json") +@Path("/whoami") +public class WhoAmIResource { + + @Inject + SecurityIdentity securityIdentity; + + @Authenticated + @GET + @Path("/") + @Counted(name = "getCurrentUserChecks", description = "How many times the current user data was requested") + public BasicUserRepresentation getCurrentUser(@Context SecurityContext ctx) { + String authenticationScheme = ctx.getAuthenticationScheme(); + + Principal principal = securityIdentity.getPrincipal(); + + String username = principal.getName(); + Set roles = securityIdentity.getRoles(); + + // Generate result + BasicUserRepresentation result = new BasicUserRepresentation(); + result.setUsername(username); + result.setPermissions(roles.stream().sorted().collect(Collectors.toCollection(LinkedHashSet::new))); + + BasicUserEntity.find("username", username).firstResultOptional() + .ifPresent(entity -> { + result.setId(entity.id); + result.setFullName(entity.fullName); + }); + + return result; + } + +} diff --git a/src/main/java/io/github/project/openubl/searchpe/resources/interceptors/HTTPBasicAuthEnabledInterceptor.java b/src/main/java/io/github/project/openubl/searchpe/resources/interceptors/HTTPBasicAuthEnabledInterceptor.java index 149caf96..b9ba5a27 100644 --- a/src/main/java/io/github/project/openubl/searchpe/resources/interceptors/HTTPBasicAuthEnabledInterceptor.java +++ b/src/main/java/io/github/project/openubl/searchpe/resources/interceptors/HTTPBasicAuthEnabledInterceptor.java @@ -16,7 +16,9 @@ */ package io.github.project.openubl.searchpe.resources.interceptors; +import io.github.project.openubl.searchpe.managers.FileManager; import org.eclipse.microprofile.config.inject.ConfigProperty; +import org.jboss.logging.Logger; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; @@ -27,15 +29,21 @@ @HTTPBasicAuthEnabled public class HTTPBasicAuthEnabledInterceptor { + private static final Logger LOGGER = Logger.getLogger(FileManager.class); + @ConfigProperty(name = "quarkus.http.auth.basic") - Boolean isAuthBasicEnabled; + boolean isAuthBasicEnabled; + + @ConfigProperty(name = "searchpe.disable.authorization", defaultValue = "false") + boolean disableAuthorization; @AroundInvoke public Object invoke(InvocationContext ctx) throws Exception { - if (isAuthBasicEnabled) { + if (isAuthBasicEnabled && !disableAuthorization) { return ctx.proceed(); } else { - throw new BadRequestException("HTTP Basic auth is disabled, can not proceed"); + LOGGER.warn("REST endpoint blocked: Authorization or HTTP Basic has been disabled"); + throw new BadRequestException("HTTP Basic auth is disabled or Auth has been disabled, can not proceed"); } } diff --git a/src/main/java/io/github/project/openubl/searchpe/security/DisabledAuthController.java b/src/main/java/io/github/project/openubl/searchpe/security/DisabledAuthController.java new file mode 100644 index 00000000..7e5fdecd --- /dev/null +++ b/src/main/java/io/github/project/openubl/searchpe/security/DisabledAuthController.java @@ -0,0 +1,40 @@ +/* + * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates + * and other contributors as indicated by the @author tags. + * + * 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. + */ +package io.github.project.openubl.searchpe.security; + +import io.quarkus.security.spi.runtime.AuthorizationController; +import org.eclipse.microprofile.config.inject.ConfigProperty; + +import javax.annotation.Priority; +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.inject.Alternative; +import javax.interceptor.Interceptor; + +@Alternative +@Priority(Interceptor.Priority.LIBRARY_AFTER) +@ApplicationScoped +public class DisabledAuthController extends AuthorizationController { + + @ConfigProperty(name = "searchpe.disable.authorization", defaultValue = "false") + boolean disableAuthorization; + + @Override + public boolean isAuthorizationEnabled() { + return !disableAuthorization; + } + +} diff --git a/src/main/resources/application-enterprise.properties b/src/main/resources/application-enterprise.properties deleted file mode 100644 index 1f52354e..00000000 --- a/src/main/resources/application-enterprise.properties +++ /dev/null @@ -1,43 +0,0 @@ -# Elasticsearch -quarkus.hibernate-search-orm.enabled=true - -quarkus.hibernate-search-orm.elasticsearch.analysis.configurer=bean:searchpeAnalysisConfigurer -quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true -quarkus.hibernate-search-orm.elasticsearch.protocol=HTTP -quarkus.hibernate-search-orm.elasticsearch.version=7 -quarkus.hibernate-search-orm.schema-management.strategy=CREATE_OR_VALIDATE -quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=write-sync -%test.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync - -quarkus.elasticsearch.devservices.enabled=true - -# Basic HTTP Authentication -quarkus.http.auth.basic=false -quarkus.security.users.embedded.enabled=false - -# Form HTTP Authentication -quarkus.http.auth.form.enabled=false - -quarkus.http.auth.permission.login-assets.paths=/assets/* -quarkus.http.auth.permission.login-assets.policy=deny - -quarkus.http.auth.permission.basic-auth-flow.paths=/auth-switch,/login.html,/login-error.html,/signup.html,/signup-error.html,/j_security_signup -quarkus.http.auth.permission.basic-auth-flow.policy=deny - -quarkus.http.auth.permission.everything-else.paths=/* -quarkus.http.auth.permission.everything-else.policy=authenticated - -# OpenId Authentication -quarkus.oidc.enabled=true - -quarkus.oidc.client-id=searchpe -quarkus.oidc.credentials.secret=secret -quarkus.oidc.application-type=HYBRID -quarkus.oidc.token.refresh-expired=true -quarkus.oidc.token.refresh-token-time-skew=10S -quarkus.oidc.roles.source=accesstoken -quarkus.oidc.logout.path=/oidc/logout -quarkus.oidc.logout.post-logout-path=/ - -quarkus.keycloak.devservices.enabled=true -quarkus.keycloak.devservices.realm-path=openubl-realm.json diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 88acd0a5..9e008b05 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -49,11 +49,13 @@ quarkus.http.auth.form.enabled=true quarkus.http.auth.form.cookie-name=searchpe-credential quarkus.http.auth.form.location-cookie=searchpe-redirect-location -quarkus.http.auth.session.encryption-key=N50xtHmAqRfL0CO7Yej5RvRsvQKeyRcesVDJc8a0Wq0= quarkus.http.auth.form.login-page=/auth-switch quarkus.http.auth.form.error-page=/login-error.html +quarkus.http.auth.session.encryption-key=N50xtHmAqRfL0CO7Yej5RvRsvQKeyRcesVDJc8a0Wq0= + +# Permissions quarkus.http.auth.permission.login-assets.paths=/assets/* quarkus.http.auth.permission.login-assets.policy=permit @@ -67,13 +69,27 @@ quarkus.http.auth.permission.everything-else.policy=authenticated quarkus.http.auth.permission.health-check.paths=/q/* quarkus.http.auth.permission.health-check.policy=permit -# Oidc Auth -quarkus.oidc.enabled=false +# Oidc Authentication +quarkus.oidc.enabled=true + +quarkus.oidc.client-id=searchpe +quarkus.oidc.credentials.secret=secret +quarkus.oidc.application-type=HYBRID +quarkus.oidc.token.refresh-expired=true +quarkus.oidc.token.refresh-token-time-skew=10S +quarkus.oidc.roles.source=accesstoken +quarkus.oidc.logout.path=/oidc/logout +quarkus.oidc.logout.post-logout-path=/ + +quarkus.oidc.tenant-enabled=false quarkus.keycloak.devservices.enabled=false +quarkus.keycloak.devservices.realm-path=openubl-realm.json # Searchpe -searchpe.sunat.padronReducidoUrl=https://raw.githubusercontent.com/project-openubl/searchpe/master/src/test/resources/padron_reducido_ruc.zip +searchpe.disable.authorization=true + +searchpe.sunat.padronReducidoUrl="https://raw.githubusercontent.com/project-openubl/searchpe/master/src/test/resources/padron_reducido_ruc.zip" searchpe.sunat.filter=ACTIVO searchpe.sunat.workspace.directory=searchpe/workspace searchpe.sunat.workspace.connectionTimeout=100000 @@ -84,4 +100,23 @@ searchpe.scheduled.cron-clean=0 0 6 * * ? searchpe.oidc.ui-client-id=searchpe-ui -%prod.searchpe.sunat.padronReducidoUrl=http://www2.sunat.gob.pe/padron_reducido_ruc.zip +# Profiles +%test.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=sync + +%prod.searchpe.sunat.padronReducidoUrl="http://www2.sunat.gob.pe/padron_reducido_ruc.zip" + +%basic.searchpe.disable.authorization=false + +%oidc.searchpe.disable.authorization=false +%oidc.quarkus.oidc.tenant-enabled=true +%oidc.quarkus.keycloak.devservices.enabled=true +%oidc.quarkus.keycloak.devservices.realm-path=openubl-realm.json + +%search.quarkus.hibernate-search-orm.enabled=true +%search.quarkus.hibernate-search-orm.elasticsearch.analysis.configurer=bean:searchpeAnalysisConfigurer +%search.quarkus.hibernate-search-orm.elasticsearch.version-check.enabled=true +%search.quarkus.hibernate-search-orm.elasticsearch.protocol=HTTP +%search.quarkus.hibernate-search-orm.elasticsearch.version=7 +%search.quarkus.hibernate-search-orm.schema-management.strategy=CREATE_OR_VALIDATE +%search.quarkus.hibernate-search-orm.automatic-indexing.synchronization.strategy=write-sync +%search.quarkus.elasticsearch.devservices.enabled=true diff --git a/src/main/webapp/src/App.tsx b/src/main/webapp/src/App.tsx index 3a6e3811..ea9d48ee 100644 --- a/src/main/webapp/src/App.tsx +++ b/src/main/webapp/src/App.tsx @@ -23,14 +23,14 @@ import NotificationsPortal from "@redhat-cloud-services/frontend-components-noti import "@redhat-cloud-services/frontend-components-notifications/index.css"; import DeleteDialog from "./shared/containers/delete-dialog"; -import { useCurrentUserQuery } from "queries/currentUser"; +import { useWhoAmIQuery } from "queries/whoami"; import { ConfirmationContextProvider } from "@project-openubl/lib-ui"; const App: React.FC = () => { - const currentUser = useCurrentUserQuery(); + const whoAmI = useWhoAmIQuery(); - if (currentUser.isError) { + if (whoAmI.isError) { return ( @@ -67,10 +67,7 @@ const App: React.FC = () => { return ( - } - > + }> diff --git a/src/main/webapp/src/Constants.ts b/src/main/webapp/src/Constants.ts index edea4e22..9b845a20 100644 --- a/src/main/webapp/src/Constants.ts +++ b/src/main/webapp/src/Constants.ts @@ -11,7 +11,7 @@ export const ALL_PERMISSIONS: Permission[] = [ Permission.user_write, ]; -export type SEARCHPE_AUTH_METHOD = "oidc" | "basic"; +export type SEARCHPE_AUTH_METHOD = "none" | "oidc" | "basic"; interface Settings { defaultAuthMethod: SEARCHPE_AUTH_METHOD; @@ -30,11 +30,15 @@ const defaultSettings: Settings = { const SEARCHPE_SETTINGS: Settings = (window as any)["SEARCHPE_SETTINGS"] || defaultSettings; -export const isBasicAuthEnabled = (): boolean => { +export const isAuthDisabled = (): boolean => { + return SEARCHPE_SETTINGS.defaultAuthMethod === "none"; +}; + +export const isBasicDefaultAuth = (): boolean => { return SEARCHPE_SETTINGS.defaultAuthMethod === "basic"; }; -export const isOidcAuthEnabled = (): boolean => { +export const isOidcDefaultAuth = (): boolean => { return SEARCHPE_SETTINGS.defaultAuthMethod === "oidc"; }; diff --git a/src/main/webapp/src/Routes.tsx b/src/main/webapp/src/Routes.tsx index b3214742..527e4a5b 100644 --- a/src/main/webapp/src/Routes.tsx +++ b/src/main/webapp/src/Routes.tsx @@ -38,7 +38,6 @@ export const AppRoutes = () => { { Component: Profile, path: Paths.profile, - hasAny: [], hasDescendant: true, }, ]; @@ -51,9 +50,13 @@ export const AppRoutes = () => { key={index} path={hasDescendant ? `${path}/*` : path} element={ - + hasAny ? ( + + + + ) : ( - + ) } /> ))} diff --git a/src/main/webapp/src/api-client/resources/core.ts b/src/main/webapp/src/api-client/resources/core.ts index d94ca47e..1a0b0192 100644 --- a/src/main/webapp/src/api-client/resources/core.ts +++ b/src/main/webapp/src/api-client/resources/core.ts @@ -64,6 +64,7 @@ export class CurrentUserClusterResource extends ClusterResource { } export enum CoreClusterResourceKind { + WhoAmI = "whoami", Version = "versions", Contribuyente = "contribuyentes", } @@ -73,7 +74,6 @@ export enum AdminClusterResourceKind { } export enum CurrentUserClusterResourceKind { - WhoAmI = "whoami", Credentials = "credentials", Profile = "profile", } diff --git a/src/main/webapp/src/api/models.tsx b/src/main/webapp/src/api/models.tsx index 3c596726..243853f7 100644 --- a/src/main/webapp/src/api/models.tsx +++ b/src/main/webapp/src/api/models.tsx @@ -73,6 +73,7 @@ export interface User { username: string; password?: string; permissions?: Permission[]; + authenticationScheme?: "Basic" | "Bearer"; } export interface UserPasswordChange { diff --git a/src/main/webapp/src/pages/contribuyentes/contribuyentes.tsx b/src/main/webapp/src/pages/contribuyentes/contribuyentes.tsx index 5adcd968..27b9f581 100644 --- a/src/main/webapp/src/pages/contribuyentes/contribuyentes.tsx +++ b/src/main/webapp/src/pages/contribuyentes/contribuyentes.tsx @@ -91,7 +91,7 @@ export const Contribuyentes: React.FC = () => { data: modalData, open: openModal, close: closeModal, - } = useModal(); + } = useModal<"view", Contribuyente>(); const [filterText, setFilterText] = useState(""); const { @@ -129,7 +129,7 @@ export const Contribuyentes: React.FC = () => { extraData: IExtraData ) => { const row: Contribuyente = getRow(rowData); - openModal(row); + openModal("view", row); }, }, ]; diff --git a/src/main/webapp/src/pages/profile/overview.tsx b/src/main/webapp/src/pages/profile/overview.tsx index ff8139eb..d4436b41 100644 --- a/src/main/webapp/src/pages/profile/overview.tsx +++ b/src/main/webapp/src/pages/profile/overview.tsx @@ -29,10 +29,9 @@ import { object, string } from "yup"; import { AxiosError } from "axios"; import { useConfirmationContext } from "@project-openubl/lib-ui"; -import { - useCurrentUserQuery, - useUpdateCurrentUserProfileMutation, -} from "queries/currentUser"; +import { useWhoAmIQuery } from "queries/whoami"; +import { useUpdateCurrentUserProfileMutation } from "queries/currentUser"; + import { getAxiosErrorMessage, getValidatedFromError, @@ -43,7 +42,7 @@ import { User } from "api/models"; export const Overview: React.FC = () => { const confirmation = useConfirmationContext(); - const currentUser = useCurrentUserQuery(); + const whoAmI = useWhoAmIQuery(); // Form @@ -59,8 +58,8 @@ export const Overview: React.FC = () => { control, } = useForm({ defaultValues: { - username: currentUser.data?.username || "", - fullName: currentUser.data?.fullName || "", + username: whoAmI.data?.username || "", + fullName: whoAmI.data?.fullName || "", }, resolver: yupResolver(validationSchema), mode: "onChange", @@ -68,7 +67,7 @@ export const Overview: React.FC = () => { const onSubmit = (formValues: FieldValues) => { const user: User = { - ...currentUser.data, + ...whoAmI.data, username: formValues.username, fullName: formValues.fullName, }; @@ -197,7 +196,7 @@ export const Overview: React.FC = () => { variant={SelectVariant.typeaheadMulti} aria-label="permissions" onToggle={() => {}} - selections={currentUser.data?.permissions} + selections={whoAmI.data?.permissions} aria-labelledby="permissions" isDisabled={true} > diff --git a/src/main/webapp/src/queries/currentUser.ts b/src/main/webapp/src/queries/currentUser.ts index aad51a38..b7d696d0 100644 --- a/src/main/webapp/src/queries/currentUser.ts +++ b/src/main/webapp/src/queries/currentUser.ts @@ -1,10 +1,4 @@ -import { - UseQueryResult, - useQuery, - UseMutationResult, - useQueryClient, - useMutation, -} from "react-query"; +import { UseMutationResult, useQueryClient, useMutation } from "react-query"; import { CurrentUserClusterResource, @@ -16,9 +10,6 @@ import { User, UserPasswordChange } from "api/models"; import { useSearchpeClient } from "./fetchHelpers"; import { AxiosError } from "axios"; -const whoAmIResource = new CurrentUserClusterResource( - CurrentUserClusterResourceKind.WhoAmI -); const profileResource = new CurrentUserClusterResource( CurrentUserClusterResourceKind.Profile ); @@ -26,19 +17,6 @@ const credentialsResource = new CurrentUserClusterResource( CurrentUserClusterResourceKind.Credentials ); -export const useCurrentUserQuery = (): UseQueryResult => { - const client = useSearchpeClient(); - const result = useQuery({ - queryKey: "currentUser", - queryFn: async () => { - return (await client.get(whoAmIResource, "")).data; - }, - refetchInterval: 60_000, - retry: process.env.NODE_ENV === "development" ? false : undefined, - }); - return result; -}; - export const useUpdateCurrentUserProfileMutation = ( onSuccess: () => void, onError: (err: AxiosError) => void @@ -52,7 +30,7 @@ export const useUpdateCurrentUserProfileMutation = ( { onSuccess: () => { queryClient.invalidateQueries("users"); - queryClient.invalidateQueries("currentUser"); + queryClient.invalidateQueries("whoami"); onSuccess && onSuccess(); }, onError, diff --git a/src/main/webapp/src/queries/whoami.ts b/src/main/webapp/src/queries/whoami.ts new file mode 100644 index 00000000..0eb509ca --- /dev/null +++ b/src/main/webapp/src/queries/whoami.ts @@ -0,0 +1,22 @@ +import { UseQueryResult, useQuery } from "react-query"; + +import { CoreClusterResource, CoreClusterResourceKind } from "api-client"; +import { ApiClientError } from "api-client/types"; + +import { User } from "api/models"; +import { useSearchpeClient } from "./fetchHelpers"; + +const whoAmIResource = new CoreClusterResource(CoreClusterResourceKind.WhoAmI); + +export const useWhoAmIQuery = (): UseQueryResult => { + const client = useSearchpeClient(); + const result = useQuery({ + queryKey: "whoami", + queryFn: async () => { + return (await client.get(whoAmIResource, "")).data; + }, + refetchInterval: 60_000, + retry: process.env.NODE_ENV === "development" ? false : undefined, + }); + return result; +}; diff --git a/src/main/webapp/src/shared/components/layout/HeaderApp/BasicMenuDropdownItems.tsx b/src/main/webapp/src/shared/components/layout/HeaderApp/BasicMenuDropdownItems.tsx deleted file mode 100644 index b88b8904..00000000 --- a/src/main/webapp/src/shared/components/layout/HeaderApp/BasicMenuDropdownItems.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from "react"; -import { useNavigate } from "react-router-dom"; -import { DropdownItem, DropdownSeparator } from "@patternfly/react-core"; -import { Paths } from "Paths"; -import { getAuthFormCookieName } from "Constants"; - -export const BasicMenuDropdownItems: React.FC = () => { - const navigate = useNavigate(); - const profile = () => { - navigate(Paths.profile); - }; - - const logout = () => { - document.cookie = `${getAuthFormCookieName()}=; Max-Age=0`; - window.location.reload(); - }; - - return ( - <> - - Profile - - - - Logout - - - ); -}; diff --git a/src/main/webapp/src/shared/components/layout/HeaderApp/HeaderApp.tsx b/src/main/webapp/src/shared/components/layout/HeaderApp/HeaderApp.tsx index f7ffcb9a..580db8fe 100644 --- a/src/main/webapp/src/shared/components/layout/HeaderApp/HeaderApp.tsx +++ b/src/main/webapp/src/shared/components/layout/HeaderApp/HeaderApp.tsx @@ -12,7 +12,7 @@ import { import { HelpIcon } from "@patternfly/react-icons"; import { AppAboutModalState } from "../AppAboutModalState"; -import { SSOMenu } from "./SSOMenu"; +import { UserDropdown } from "./UserDropdown"; import { MobileDropdown } from "./MobileDropdown"; import navBrandImage from "images/logo-navbar.svg"; @@ -52,7 +52,7 @@ export const HeaderApp: React.FC = () => { > - + diff --git a/src/main/webapp/src/shared/components/layout/HeaderApp/OidcMenuDropdownItems.tsx b/src/main/webapp/src/shared/components/layout/HeaderApp/OidcMenuDropdownItems.tsx deleted file mode 100644 index bce3c718..00000000 --- a/src/main/webapp/src/shared/components/layout/HeaderApp/OidcMenuDropdownItems.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; -import { DropdownItem } from "@patternfly/react-core"; -import { getOidcLogoutPath } from "Constants"; - -export const OidcMenuDropdownItems: React.FC = () => { - return ( - <> - { - window.location.replace(getOidcLogoutPath()); - }} - > - Logout - - - ); -}; diff --git a/src/main/webapp/src/shared/components/layout/HeaderApp/SSOMenu.tsx b/src/main/webapp/src/shared/components/layout/HeaderApp/SSOMenu.tsx deleted file mode 100644 index ec4f938f..00000000 --- a/src/main/webapp/src/shared/components/layout/HeaderApp/SSOMenu.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import React, { useState } from "react"; -import { - Dropdown, - DropdownGroup, - DropdownToggle, - PageHeaderToolsItem, -} from "@patternfly/react-core"; - -import { useCurrentUserQuery } from "queries/currentUser"; -import { isBasicAuthEnabled, isOidcAuthEnabled } from "Constants"; - -import { BasicMenuDropdownItems } from "./BasicMenuDropdownItems"; -import { OidcMenuDropdownItems } from "./OidcMenuDropdownItems"; - -export const SSOMenu: React.FC = () => { - const currentUser = useCurrentUserQuery(); - - const [isDropdownOpen, setIsDropdownOpen] = useState(false); - const onDropdownSelect = () => { - setIsDropdownOpen((current) => !current); - }; - const onDropdownToggle = (isOpen: boolean) => { - setIsDropdownOpen(isOpen); - }; - - let authDropdownItems; - if (isBasicAuthEnabled()) { - authDropdownItems = ; - } else if (isOidcAuthEnabled()) { - authDropdownItems = ; - } - - return ( - - ); -}; diff --git a/src/main/webapp/src/shared/components/layout/HeaderApp/UserDropdown.tsx b/src/main/webapp/src/shared/components/layout/HeaderApp/UserDropdown.tsx new file mode 100644 index 00000000..9bd282fe --- /dev/null +++ b/src/main/webapp/src/shared/components/layout/HeaderApp/UserDropdown.tsx @@ -0,0 +1,86 @@ +import React, { useState } from "react"; +import { useNavigate } from "react-router-dom"; +import { + Dropdown, + DropdownGroup, + DropdownItem, + DropdownToggle, + PageHeaderToolsItem, +} from "@patternfly/react-core"; + +import { useWhoAmIQuery } from "queries/whoami"; + +import { + getAuthFormCookieName, + getOidcLogoutPath, + isAuthDisabled, + isBasicDefaultAuth, + isOidcDefaultAuth, +} from "Constants"; + +import { Paths } from "Paths"; + +export const UserDropdown: React.FC = () => { + const navigate = useNavigate(); + const whoAmI = useWhoAmIQuery(); + + const [isDropdownOpen, setIsDropdownOpen] = useState(false); + const onDropdownSelect = () => { + setIsDropdownOpen((current) => !current); + }; + const onDropdownToggle = (isOpen: boolean) => { + setIsDropdownOpen(isOpen); + }; + + const profile = () => { + navigate(Paths.profile); + }; + + const logout = () => { + if (isBasicDefaultAuth()) { + document.cookie = `${getAuthFormCookieName()}=; Max-Age=0`; + window.location.reload(); + } else if (isOidcDefaultAuth()) { + window.location.replace(getOidcLogoutPath()); + } + }; + + return ( + + ); +}; diff --git a/src/main/webapp/src/shared/components/layout/SidebarApp/SidebarApp.tsx b/src/main/webapp/src/shared/components/layout/SidebarApp/SidebarApp.tsx index 849b7f9c..ddb06648 100644 --- a/src/main/webapp/src/shared/components/layout/SidebarApp/SidebarApp.tsx +++ b/src/main/webapp/src/shared/components/layout/SidebarApp/SidebarApp.tsx @@ -5,11 +5,7 @@ import { Nav, PageSidebar, NavList } from "@patternfly/react-core"; import { css } from "@patternfly/react-styles"; import { Paths } from "Paths"; -import { - isElasticsearchEnabled, - isBasicAuthEnabled, - Permission, -} from "Constants"; +import { isAuthDisabled, Permission } from "Constants"; import { LayoutTheme } from "../LayoutUtils"; import { VisibilityByPermission } from "shared/containers"; @@ -21,16 +17,14 @@ export const SidebarApp: React.FC = () => { - {isElasticsearchEnabled() && ( - - css("pf-c-nav__link", isActive ? "pf-m-current" : "") - } - > - Buscar - - )} + + css("pf-c-nav__link", isActive ? "pf-m-current" : "") + } + > + Buscar + @@ -52,7 +46,7 @@ export const SidebarApp: React.FC = () => { Versiones - {isBasicAuthEnabled() && ( + {!isAuthDisabled() && ( diff --git a/src/main/webapp/src/shared/hooks/usePermission/usePermission.ts b/src/main/webapp/src/shared/hooks/usePermission/usePermission.ts index edb772f1..04fe4785 100644 --- a/src/main/webapp/src/shared/hooks/usePermission/usePermission.ts +++ b/src/main/webapp/src/shared/hooks/usePermission/usePermission.ts @@ -1,5 +1,5 @@ -import { Permission } from "Constants"; -import { useCurrentUserQuery } from "queries/currentUser"; +import { isAuthDisabled, Permission } from "Constants"; +import { useWhoAmIQuery } from "queries/whoami"; export interface IArgs { hasAny: Permission[]; @@ -10,17 +10,15 @@ export interface IState { } export const usePermission = ({ hasAny }: IArgs): IState => { - const currentUser = useCurrentUserQuery(); + const whoAmI = useWhoAmIQuery(); - const userPermissions = currentUser.data?.permissions || []; - const isAllowed = - hasAny.length === 0 || - hasAny.some((permission) => { - return userPermissions.some((f) => f === permission); - }); + const userPermissions = whoAmI.data?.permissions || []; + const isAllowed = hasAny.some((permission) => { + return userPermissions.some((f) => f === permission); + }); return { - isAllowed, + isAllowed: isAllowed || isAuthDisabled(), }; }; diff --git a/src/test/java/io/github/project/openubl/searchpe/AbstractBaseTest.java b/src/test/java/io/github/project/openubl/searchpe/AbstractBaseTest.java index 9448ce6e..57a74092 100644 --- a/src/test/java/io/github/project/openubl/searchpe/AbstractBaseTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/AbstractBaseTest.java @@ -79,7 +79,7 @@ private Flyway flyway() { protected RequestSpecification givenAuth(String username) { Config config = ConfigProvider.getConfig(); - Boolean oidcEnabled = config.getValue("quarkus.oidc.enabled", Boolean.class); + Boolean oidcEnabled = config.getValue("quarkus.oidc.tenant-enabled", Boolean.class); if (oidcEnabled) { return given().auth().oauth2(getAccessToken(username)); } else { diff --git a/src/test/java/io/github/project/openubl/searchpe/EnterpriseProfileManager.java b/src/test/java/io/github/project/openubl/searchpe/BasicProfileManager.java similarity index 83% rename from src/test/java/io/github/project/openubl/searchpe/EnterpriseProfileManager.java rename to src/test/java/io/github/project/openubl/searchpe/BasicProfileManager.java index 2a58be18..3af4d4c6 100644 --- a/src/test/java/io/github/project/openubl/searchpe/EnterpriseProfileManager.java +++ b/src/test/java/io/github/project/openubl/searchpe/BasicProfileManager.java @@ -16,10 +16,11 @@ */ package io.github.project.openubl.searchpe; -public class EnterpriseProfileManager extends ProfileManager { +public class BasicProfileManager extends ProfileManager { - public EnterpriseProfileManager() { - super(DistributionFlavor.enterprise); + @Override + public String getProfile() { + return "basic"; } } diff --git a/src/test/java/io/github/project/openubl/searchpe/StandaloneProfileManager.java b/src/test/java/io/github/project/openubl/searchpe/DefaultProfileManager.java similarity index 83% rename from src/test/java/io/github/project/openubl/searchpe/StandaloneProfileManager.java rename to src/test/java/io/github/project/openubl/searchpe/DefaultProfileManager.java index 95be0972..40ea5183 100644 --- a/src/test/java/io/github/project/openubl/searchpe/StandaloneProfileManager.java +++ b/src/test/java/io/github/project/openubl/searchpe/DefaultProfileManager.java @@ -16,10 +16,11 @@ */ package io.github.project.openubl.searchpe; -public class StandaloneProfileManager extends ProfileManager { +public class DefaultProfileManager extends ProfileManager { - public StandaloneProfileManager() { - super(DistributionFlavor.standalone); + @Override + public String getProfile() { + return ""; } } diff --git a/src/test/java/io/github/project/openubl/searchpe/FlywayTestCallback.java b/src/test/java/io/github/project/openubl/searchpe/FlywayTestCallback.java deleted file mode 100644 index 4fc1a541..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/FlywayTestCallback.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe; - -import io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback; -import io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback; -import io.quarkus.test.junit.callback.QuarkusTestMethodContext; -import org.eclipse.microprofile.config.Config; -import org.eclipse.microprofile.config.ConfigProvider; -import org.flywaydb.core.Flyway; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.regex.Matcher; - -public class FlywayTestCallback implements QuarkusTestBeforeEachCallback, QuarkusTestAfterEachCallback { - - @Override - public void beforeEach(QuarkusTestMethodContext context) { - Flyway flyway = flyway(context); - flyway.clean(); - flyway.migrate(); - } - - @Override - public void afterEach(QuarkusTestMethodContext context) { - Flyway flyway = flyway(context); - flyway.clean(); - } - - private Flyway flyway(final QuarkusTestMethodContext context) { - Config config = ConfigProvider.getConfig(); - String username = config.getValue("quarkus.datasource.username", String.class); - String password = config.getValue("quarkus.datasource.password", String.class); - String jdbUrl = config.getValue("quarkus.datasource.jdbc.url", String.class); - - // Flyway - final String packageName = context.getTestInstance().getClass().getName(); - final String testDefaultLocation = "db/" + packageName.replaceAll("\\.", Matcher.quoteReplacement(File.separator)); - - final List locations = new ArrayList<>(); - locations.add(testDefaultLocation); - locations.add("db" + File.separator + "migration"); - - if (packageName.startsWith("Native") && packageName.endsWith("IT")) { - final String className = context.getTestInstance().getClass().getSimpleName(); - final String nativeClassName = className.replaceFirst("Native", "").replace("IT", "Test"); - final String testNativeDefaultLocation = "db/" + context.getTestInstance().getClass().getPackage().getName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + "/" + nativeClassName; - - locations.add(testNativeDefaultLocation); - } - - return Flyway.configure() - .dataSource(jdbUrl, username, password) - .connectRetries(120) - .locations(locations.toArray(String[]::new)) - .load(); - } - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/ProfileManager.java b/src/test/java/io/github/project/openubl/searchpe/ProfileManager.java index 9c44ea41..c9f6892b 100644 --- a/src/test/java/io/github/project/openubl/searchpe/ProfileManager.java +++ b/src/test/java/io/github/project/openubl/searchpe/ProfileManager.java @@ -24,41 +24,17 @@ public abstract class ProfileManager implements QuarkusTestProfile { - enum DistributionFlavor { - standalone, enterprise - } - - protected String configProfile; - protected List testResources = new ArrayList<>(); + private List testResources = new ArrayList<>(); - public ProfileManager(DistributionFlavor distributionFlavor) { - init(distributionFlavor); + public ProfileManager() { + testResources.add(new TestResourceEntry(SunatServer.class)); } - private void init(DistributionFlavor distributionFlavor) { - switch (distributionFlavor) { - case standalone: - // Profile - configProfile = DistributionFlavor.standalone.toString(); - - // Test resources - testResources.add(new TestResourceEntry(SunatServer.class)); - - break; - case enterprise: - // Profile - configProfile = DistributionFlavor.enterprise.toString(); - - // Test resources - testResources.add(new TestResourceEntry(SunatServer.class)); - - break; - } - } + public abstract String getProfile(); @Override public String getConfigProfile() { - return "test," + configProfile; + return "test," + getProfile(); } @Override diff --git a/src/test/java/io/github/project/openubl/searchpe/idm/validators/ValidPermissionValidatorTest.java b/src/test/java/io/github/project/openubl/searchpe/idm/validators/ValidPermissionValidatorTest.java index 820577cb..eaf5046f 100644 --- a/src/test/java/io/github/project/openubl/searchpe/idm/validators/ValidPermissionValidatorTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/idm/validators/ValidPermissionValidatorTest.java @@ -16,7 +16,7 @@ */ package io.github.project.openubl.searchpe.idm.validators; -import io.github.project.openubl.searchpe.StandaloneProfileManager; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.github.project.openubl.searchpe.security.Permission; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; @@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest -@TestProfile(StandaloneProfileManager.class) +@TestProfile(DefaultProfileManager.class) public class ValidPermissionValidatorTest { @Inject diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractContribuyenteResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteResourceTest.java similarity index 85% rename from src/test/java/io/github/project/openubl/searchpe/resources/AbstractContribuyenteResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteResourceTest.java index acf4033d..96898837 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractContribuyenteResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteResourceTest.java @@ -17,17 +17,22 @@ package io.github.project.openubl.searchpe.resources; import io.github.project.openubl.searchpe.AbstractBaseTest; +import io.github.project.openubl.searchpe.BasicProfileManager; import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.is; +@QuarkusTest +@TestProfile(BasicProfileManager.class) @TestHTTPEndpoint(ContribuyenteResource.class) -public abstract class AbstractContribuyenteResourceTest extends AbstractBaseTest { +public class ContribuyenteResourceTest extends AbstractBaseTest { @Override public Class getTestClass() { - return AbstractContribuyenteResourceTest.class; + return ContribuyenteResourceTest.class; } @Test diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseSearchContribuyenteResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteSearchResourceTest.java similarity index 96% rename from src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseSearchContribuyenteResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteSearchResourceTest.java index 60d91909..37862062 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseSearchContribuyenteResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/ContribuyenteSearchResourceTest.java @@ -17,7 +17,7 @@ package io.github.project.openubl.searchpe.resources; import io.github.project.openubl.searchpe.AbstractBaseTest; -import io.github.project.openubl.searchpe.EnterpriseProfileManager; +import io.github.project.openubl.searchpe.BasicProfileManager; import io.github.project.openubl.searchpe.models.jpa.entity.Status; import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity; import io.quarkus.test.junit.QuarkusTest; @@ -31,12 +31,12 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; @QuarkusTest -@TestProfile(EnterpriseProfileManager.class) -public class EnterpriseSearchContribuyenteResourceTest extends AbstractBaseTest { +@TestProfile(BasicProfileManager.class) +public class ContribuyenteSearchResourceTest extends AbstractBaseTest { @Override public Class getTestClass() { - return EnterpriseSearchContribuyenteResourceTest.class; + return ContribuyenteSearchResourceTest.class; } @Test diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneCurrentUserResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/CurrentUserResourceTest.java similarity index 67% rename from src/test/java/io/github/project/openubl/searchpe/resources/StandaloneCurrentUserResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/CurrentUserResourceTest.java index 14c5e04a..e8d217d4 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneCurrentUserResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/CurrentUserResourceTest.java @@ -16,19 +16,32 @@ */ package io.github.project.openubl.searchpe.resources; -import io.github.project.openubl.searchpe.StandaloneProfileManager; +import io.github.project.openubl.searchpe.AbstractBaseTest; +import io.github.project.openubl.searchpe.BasicProfileManager; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.github.project.openubl.searchpe.idm.BasicUserPasswordChangeRepresentation; +import io.quarkus.test.common.http.TestHTTPEndpoint; import io.quarkus.test.junit.QuarkusTest; import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; import java.util.List; +import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; @QuarkusTest -@TestProfile(StandaloneProfileManager.class) -public class StandaloneCurrentUserResourceTest extends AbstractCurrentUserResourceTest { +@TestProfile(BasicProfileManager.class) +@TestHTTPEndpoint(CurrentUserResource.class) +public class CurrentUserResourceTest extends AbstractBaseTest { + + @Override + public Class getTestClass() { + return CurrentUserResourceTest.class; + } @Test public void updateCredentials() { diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseContribuyenteResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseContribuyenteResourceTest.java deleted file mode 100644 index c2373cd6..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseContribuyenteResourceTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.EnterpriseProfileManager; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; - -@QuarkusTest -@TestProfile(EnterpriseProfileManager.class) -public class EnterpriseContribuyenteResourceTest extends AbstractContribuyenteResourceTest { - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseCurrentUserResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseCurrentUserResourceTest.java deleted file mode 100644 index f78239fe..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseCurrentUserResourceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.EnterpriseProfileManager; -import io.github.project.openubl.searchpe.idm.BasicUserPasswordChangeRepresentation; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; -import org.junit.jupiter.api.Test; - -@QuarkusTest -@TestProfile(EnterpriseProfileManager.class) -public class EnterpriseCurrentUserResourceTest extends AbstractCurrentUserResourceTest { - - @Test - public void updateCredentials() { - BasicUserPasswordChangeRepresentation rep = new BasicUserPasswordChangeRepresentation(); - rep.setNewPassword("newPassword"); - - givenAuth("alice") - .header("Content-Type", "application/json") - .when() - .body(rep) - .post("/credentials") - .then() - .statusCode(400); - } - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseUserResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseUserResourceTest.java deleted file mode 100644 index 07309d1f..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/EnterpriseUserResourceTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.AbstractBaseTest; -import io.github.project.openubl.searchpe.EnterpriseProfileManager; -import io.github.project.openubl.searchpe.idm.BasicUserRepresentation; -import io.github.project.openubl.searchpe.models.jpa.entity.BasicUserEntity; -import io.github.project.openubl.searchpe.security.Permission; -import io.quarkus.test.common.http.TestHTTPEndpoint; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; -import org.junit.jupiter.api.Test; - -import java.util.HashSet; -import java.util.List; - -@QuarkusTest -@TestProfile(EnterpriseProfileManager.class) -@TestHTTPEndpoint(BasicUserResource.class) -public class EnterpriseUserResourceTest extends AbstractBaseTest { - - @Override - public Class getTestClass() { - return EnterpriseUserResourceTest.class; - } - - @Test - public void getDefaultUsers() { - givenAuth("admin") - .header("Content-Type", "application/json") - .when() - .get("/") - .then() - .statusCode(400); - } - - @Test - public void getOneUser() { - givenAuth("admin") - .header("Content-Type", "application/json") - .when() - .get("/1") - .then() - .statusCode(400); - } - - @Test - public void updateUser() { - // Given - BasicUserEntity userToUpdate = new BasicUserEntity(); - userToUpdate.username = "newUsername"; - userToUpdate.password = "newPassword"; - - // Then - givenAuth("admin") - .header("Content-Type", "application/json") - .when() - .body(userToUpdate) - .put("/1") - .then() - .statusCode(400); - } - - @Test - public void deleteUser() { - givenAuth("admin") - .header("Content-Type", "application/json") - .when() - .get("/1") - .then() - .statusCode(400); - } - - @Test - public void createUser() { - // Given - BasicUserRepresentation user = new BasicUserRepresentation(); - user.setUsername("myUsername"); - user.setPassword("myPassword"); - user.setPermissions(new HashSet<>(List.of(Permission.search))); - - // When - givenAuth("admin") - .header("Content-Type", "application/json") - .when() - .body(user) - .post("/") - .then() - .statusCode(400); - } - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseContribuyenteResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseContribuyenteResourceIT.java deleted file mode 100644 index 2831f9de..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseContribuyenteResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeEnterpriseContribuyenteResourceIT extends EnterpriseContribuyenteResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseCurrentUserResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseCurrentUserResourceIT.java deleted file mode 100644 index a02f27c3..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseCurrentUserResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeEnterpriseCurrentUserResourceIT extends EnterpriseCurrentUserResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseVersionResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseVersionResourceIT.java deleted file mode 100644 index d91e0726..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeEnterpriseVersionResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeEnterpriseVersionResourceIT extends EnterpriseVersionResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneContribuyenteResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneContribuyenteResourceIT.java deleted file mode 100644 index 3b37b18b..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneContribuyenteResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeStandaloneContribuyenteResourceIT extends StandaloneContribuyenteResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneCurrentUserResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneCurrentUserResourceIT.java deleted file mode 100644 index d13b88d6..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneCurrentUserResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeStandaloneCurrentUserResourceIT extends StandaloneCurrentUserResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneVersionResourceIT.java b/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneVersionResourceIT.java deleted file mode 100644 index b4c52b39..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/NativeStandaloneVersionResourceIT.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.quarkus.test.junit.QuarkusIntegrationTest; -import org.junit.jupiter.api.Disabled; - -@Disabled -@QuarkusIntegrationTest -public class NativeStandaloneVersionResourceIT extends StandaloneVersionResourceTest { -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneContribuyenteResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneContribuyenteResourceTest.java deleted file mode 100644 index cd96e2e2..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneContribuyenteResourceTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.StandaloneProfileManager; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; - -@QuarkusTest -@TestProfile(StandaloneProfileManager.class) -public class StandaloneContribuyenteResourceTest extends AbstractContribuyenteResourceTest { - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneSearchContribuyenteResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneSearchContribuyenteResourceTest.java deleted file mode 100644 index 863db9d8..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneSearchContribuyenteResourceTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.AbstractBaseTest; -import io.github.project.openubl.searchpe.StandaloneProfileManager; -import io.quarkus.test.common.http.TestHTTPEndpoint; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; -import org.junit.jupiter.api.Test; - -@QuarkusTest -@TestProfile(StandaloneProfileManager.class) -@TestHTTPEndpoint(ContribuyenteResource.class) -public class StandaloneSearchContribuyenteResourceTest extends AbstractBaseTest { - - @Override - public Class getTestClass() { - return StandaloneSearchContribuyenteResourceTest.class; - } - - @Test - public void getContribuyentes() { - givenAuth("alice") - .header("Content-Type", "application/json") - .when() - .get("/") - .then() - .statusCode(404); - } - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneVersionResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneVersionResourceTest.java deleted file mode 100644 index 6d0d677c..00000000 --- a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneVersionResourceTest.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Project OpenUBL, Inc. and/or its affiliates - * and other contributors as indicated by the @author tags. - * - * 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. - */ -package io.github.project.openubl.searchpe.resources; - -import io.github.project.openubl.searchpe.StandaloneProfileManager; -import io.quarkus.test.junit.QuarkusTest; -import io.quarkus.test.junit.TestProfile; - -@QuarkusTest -@TestProfile(StandaloneProfileManager.class) -public class StandaloneVersionResourceTest extends AbstractVersionResourceTest { - -} diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneUserResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/UserResourceTest.java similarity index 97% rename from src/test/java/io/github/project/openubl/searchpe/resources/StandaloneUserResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/UserResourceTest.java index fec34103..15368957 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/StandaloneUserResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/UserResourceTest.java @@ -17,7 +17,8 @@ package io.github.project.openubl.searchpe.resources; import io.github.project.openubl.searchpe.AbstractBaseTest; -import io.github.project.openubl.searchpe.StandaloneProfileManager; +import io.github.project.openubl.searchpe.BasicProfileManager; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.github.project.openubl.searchpe.idm.BasicUserRepresentation; import io.github.project.openubl.searchpe.security.Permission; import io.quarkus.test.common.http.TestHTTPEndpoint; @@ -33,13 +34,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; @QuarkusTest -@TestProfile(StandaloneProfileManager.class) +@TestProfile(BasicProfileManager.class) @TestHTTPEndpoint(BasicUserResource.class) -public class StandaloneUserResourceTest extends AbstractBaseTest { +public class UserResourceTest extends AbstractBaseTest { @Override public Class getTestClass() { - return StandaloneUserResourceTest.class; + return UserResourceTest.class; } @Test diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractVersionResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/VersionResourceTest.java similarity index 95% rename from src/test/java/io/github/project/openubl/searchpe/resources/AbstractVersionResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/VersionResourceTest.java index d735ed11..cdcdc893 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractVersionResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/VersionResourceTest.java @@ -17,9 +17,12 @@ package io.github.project.openubl.searchpe.resources; import io.github.project.openubl.searchpe.AbstractBaseTest; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.github.project.openubl.searchpe.models.jpa.entity.Status; import io.github.project.openubl.searchpe.models.jpa.entity.VersionEntity; import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; @@ -30,12 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; +@QuarkusTest +@TestProfile(DefaultProfileManager.class) @TestHTTPEndpoint(VersionResource.class) -public abstract class AbstractVersionResourceTest extends AbstractBaseTest { +public class VersionResourceTest extends AbstractBaseTest { @Override public Class getTestClass() { - return AbstractVersionResourceTest.class; + return VersionResourceTest.class; } @Test diff --git a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractCurrentUserResourceTest.java b/src/test/java/io/github/project/openubl/searchpe/resources/WhoAmIResourceTest.java similarity index 78% rename from src/test/java/io/github/project/openubl/searchpe/resources/AbstractCurrentUserResourceTest.java rename to src/test/java/io/github/project/openubl/searchpe/resources/WhoAmIResourceTest.java index b8a23c85..59dfa01a 100644 --- a/src/test/java/io/github/project/openubl/searchpe/resources/AbstractCurrentUserResourceTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/resources/WhoAmIResourceTest.java @@ -17,23 +17,24 @@ package io.github.project.openubl.searchpe.resources; import io.github.project.openubl.searchpe.AbstractBaseTest; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.quarkus.test.common.http.TestHTTPEndpoint; +import io.quarkus.test.junit.QuarkusTest; +import io.quarkus.test.junit.TestProfile; import org.junit.jupiter.api.Test; import java.util.List; -import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -@TestHTTPEndpoint(CurrentUserResource.class) -public abstract class AbstractCurrentUserResourceTest extends AbstractBaseTest { +@QuarkusTest +@TestProfile(DefaultProfileManager.class) +@TestHTTPEndpoint(WhoAmIResource.class) +public class WhoAmIResourceTest extends AbstractBaseTest { @Override public Class getTestClass() { - return AbstractCurrentUserResourceTest.class; + return WhoAmIResourceTest.class; } @Test @@ -41,7 +42,7 @@ public void whoAmITest() { givenAuth("alice") .header("Content-Type", "application/json") .when() - .get("/whoami") + .get("/") .then() .statusCode(200) .body( @@ -52,7 +53,7 @@ public void whoAmITest() { givenAuth("admin") .header("Content-Type", "application/json") .when() - .get("/whoami") + .get("/") .then() .statusCode(200) .body( diff --git a/src/test/java/io/github/project/openubl/searchpe/utils/DataHelperTest.java b/src/test/java/io/github/project/openubl/searchpe/utils/DataHelperTest.java index 8ed6f4d9..72257ff7 100644 --- a/src/test/java/io/github/project/openubl/searchpe/utils/DataHelperTest.java +++ b/src/test/java/io/github/project/openubl/searchpe/utils/DataHelperTest.java @@ -16,7 +16,7 @@ */ package io.github.project.openubl.searchpe.utils; -import io.github.project.openubl.searchpe.StandaloneProfileManager; +import io.github.project.openubl.searchpe.DefaultProfileManager; import io.github.project.openubl.searchpe.managers.FileManager; import io.github.project.openubl.searchpe.models.jpa.entity.ContribuyenteEntity; import io.quarkus.test.junit.QuarkusTest; @@ -38,7 +38,7 @@ import static org.junit.jupiter.api.Assertions.*; @QuarkusTest -@TestProfile(StandaloneProfileManager.class) +@TestProfile(DefaultProfileManager.class) public class DataHelperTest { @Inject diff --git a/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback b/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback deleted file mode 100644 index 84a4ae2e..00000000 --- a/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterEachCallback +++ /dev/null @@ -1 +0,0 @@ -#io.github.project.openubl.searchpe.FlywayTestCallback diff --git a/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback b/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback deleted file mode 100644 index 84a4ae2e..00000000 --- a/src/test/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeEachCallback +++ /dev/null @@ -1 +0,0 @@ -#io.github.project.openubl.searchpe.FlywayTestCallback diff --git a/src/test/resources/db/io/github/project/openubl/searchpe/resources/AbstractContribuyenteResourceTest/V9999.0.1__test.sql b/src/test/resources/db/io/github/project/openubl/searchpe/resources/ContribuyenteResourceTest/V9999.0.1__test.sql similarity index 100% rename from src/test/resources/db/io/github/project/openubl/searchpe/resources/AbstractContribuyenteResourceTest/V9999.0.1__test.sql rename to src/test/resources/db/io/github/project/openubl/searchpe/resources/ContribuyenteResourceTest/V9999.0.1__test.sql diff --git a/src/test/resources/db/io/github/project/openubl/searchpe/resources/AbstractVersionResourceTest/V9999.0.1__test.sql b/src/test/resources/db/io/github/project/openubl/searchpe/resources/VersionResourceTest/V9999.0.1__test.sql similarity index 100% rename from src/test/resources/db/io/github/project/openubl/searchpe/resources/AbstractVersionResourceTest/V9999.0.1__test.sql rename to src/test/resources/db/io/github/project/openubl/searchpe/resources/VersionResourceTest/V9999.0.1__test.sql