Skip to content
Snippets Groups Projects
Verified Commit f2e64511 authored by Martin Weise's avatar Martin Weise
Browse files

Fixed the tests with *magic*

parent 4c00c298
No related branches found
No related tags found
2 merge requests!374Bumped version of DBRepo,!373Bumped version of DBRepo
Showing
with 1536 additions and 1643 deletions
...@@ -59,35 +59,26 @@ paths: ...@@ -59,35 +59,26 @@ paths:
type: string type: string
format: date-time format: date-time
responses: responses:
"200": "503":
description: Retrieved view data description: Failed to establish connection with the metadata service
headers:
Access-Control-Expose-Headers:
description: Expose `X-Count` custom header
required: true
style: simple
X-Count:
description: Number of rows
required: true
style: simple
content: content:
application/json: application/json:
schema: schema:
type: string $ref: "#/components/schemas/ApiErrorDto"
"400": "404":
description: Request pagination is malformed description: Failed to find view in metadata database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"503": "409":
description: Failed to establish connection with the metadata service description: View schema could not be mapped
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404": "400":
description: Failed to find view in metadata database description: Request pagination is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -98,12 +89,21 @@ paths: ...@@ -98,12 +89,21 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"409": "200":
description: View schema could not be mapped description: Retrieved view data
headers:
Access-Control-Expose-Headers:
description: Expose `X-Count` custom header
required: true
style: simple
X-Count:
description: Number of rows
required: true
style: simple
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" type: string
security: security:
- basicAuth: [] - basicAuth: []
- bearerAuth: [] - bearerAuth: []
...@@ -147,35 +147,26 @@ paths: ...@@ -147,35 +147,26 @@ paths:
type: string type: string
format: date-time format: date-time
responses: responses:
"200": "503":
description: Retrieved view data description: Failed to establish connection with the metadata service
headers:
Access-Control-Expose-Headers:
description: Expose `X-Count` custom header
required: true
style: simple
X-Count:
description: Number of rows
required: true
style: simple
content: content:
application/json: application/json:
schema: schema:
type: string $ref: "#/components/schemas/ApiErrorDto"
"400": "404":
description: Request pagination is malformed description: Failed to find view in metadata database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"503": "409":
description: Failed to establish connection with the metadata service description: View schema could not be mapped
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404": "400":
description: Failed to find view in metadata database description: Request pagination is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -186,12 +177,21 @@ paths: ...@@ -186,12 +177,21 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"409": "200":
description: View schema could not be mapped description: Retrieved view data
headers:
Access-Control-Expose-Headers:
description: Expose `X-Count` custom header
required: true
style: simple
X-Count:
description: Number of rows
required: true
style: simple
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" type: string
security: security:
- basicAuth: [] - basicAuth: []
- bearerAuth: [] - bearerAuth: []
...@@ -237,8 +237,8 @@ paths: ...@@ -237,8 +237,8 @@ paths:
type: integer type: integer
format: int64 format: int64
responses: responses:
"403": "400":
description: Not allowed to get table data description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -270,8 +270,8 @@ paths: ...@@ -270,8 +270,8 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
"400": "403":
description: Request pagination or table data select query is malformed description: Not allowed to get table data
content: content:
application/json: application/json:
schema: schema:
...@@ -312,8 +312,8 @@ paths: ...@@ -312,8 +312,8 @@ paths:
$ref: "#/components/schemas/TupleUpdateDto" $ref: "#/components/schemas/TupleUpdateDto"
required: true required: true
responses: responses:
"403": "400":
description: Update table data not allowed description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -324,16 +324,16 @@ paths: ...@@ -324,16 +324,16 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"202":
description: Updated table data
"404": "404":
description: Failed to find table in metadata database description: Failed to find table in metadata database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400": "202":
description: Request pagination or table data select query is malformed description: Updated table data
"403":
description: Update table data not allowed
content: content:
application/json: application/json:
schema: schema:
...@@ -374,30 +374,30 @@ paths: ...@@ -374,30 +374,30 @@ paths:
$ref: "#/components/schemas/TupleDto" $ref: "#/components/schemas/TupleDto"
required: true required: true
responses: responses:
"503": "404":
description: Failed to establish connection with the metadata service or description: Failed to find table in metadata database or blob in storage
storage service service
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"403": "400":
description: Create table data not allowed description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404": "201":
description: Failed to find table in metadata database or blob in storage description: Created table data
service "503":
description: Failed to establish connection with the metadata service or
storage service
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"201": "403":
description: Created table data description: Create table data not allowed
"400":
description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -438,8 +438,8 @@ paths: ...@@ -438,8 +438,8 @@ paths:
$ref: "#/components/schemas/TupleDeleteDto" $ref: "#/components/schemas/TupleDeleteDto"
required: true required: true
responses: responses:
"403": "400":
description: Delete table data not allowed description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -450,16 +450,16 @@ paths: ...@@ -450,16 +450,16 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"202":
description: Deleted table data
"404": "404":
description: Failed to find table in metadata database description: Failed to find table in metadata database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400": "202":
description: Request pagination or table data select query is malformed description: Deleted table data
"403":
description: Delete table data not allowed
content: content:
application/json: application/json:
schema: schema:
...@@ -508,8 +508,8 @@ paths: ...@@ -508,8 +508,8 @@ paths:
type: integer type: integer
format: int64 format: int64
responses: responses:
"403": "400":
description: Not allowed to get table data description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -541,8 +541,8 @@ paths: ...@@ -541,8 +541,8 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
"400": "403":
description: Request pagination or table data select query is malformed description: Not allowed to get table data
content: content:
application/json: application/json:
schema: schema:
...@@ -573,6 +573,12 @@ paths: ...@@ -573,6 +573,12 @@ paths:
schema: schema:
type: integer type: integer
format: int64 format: int64
- name: timestamp
in: query
required: false
schema:
type: string
format: date-time
- name: page - name: page
in: query in: query
required: false required: false
...@@ -586,31 +592,12 @@ paths: ...@@ -586,31 +592,12 @@ paths:
type: integer type: integer
format: int64 format: int64
responses: responses:
"403":
description: Not allowed to retrieve subset data
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find database in metadata database or query in query
store of the data database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"503": "503":
description: Failed to communicate with database description: Failed to communicate with database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400":
description: Invalid pagination
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"200": "200":
description: Retrieved subset data description: Retrieved subset data
headers: headers:
...@@ -632,6 +619,25 @@ paths: ...@@ -632,6 +619,25 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
"400":
description: Invalid pagination
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find database in metadata database or query in query
store of the data database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"403":
description: Not allowed to retrieve subset data
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
security: security:
- bearerAuth: [] - bearerAuth: []
- basicAuth: [] - basicAuth: []
...@@ -657,6 +663,12 @@ paths: ...@@ -657,6 +663,12 @@ paths:
schema: schema:
type: integer type: integer
format: int64 format: int64
- name: timestamp
in: query
required: false
schema:
type: string
format: date-time
- name: page - name: page
in: query in: query
required: false required: false
...@@ -670,31 +682,12 @@ paths: ...@@ -670,31 +682,12 @@ paths:
type: integer type: integer
format: int64 format: int64
responses: responses:
"403":
description: Not allowed to retrieve subset data
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find database in metadata database or query in query
store of the data database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"503": "503":
description: Failed to communicate with database description: Failed to communicate with database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400":
description: Invalid pagination
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"200": "200":
description: Retrieved subset data description: Retrieved subset data
headers: headers:
...@@ -716,6 +709,25 @@ paths: ...@@ -716,6 +709,25 @@ paths:
application/json: application/json:
schema: schema:
type: string type: string
"400":
description: Invalid pagination
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find database in metadata database or query in query
store of the data database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"403":
description: Not allowed to retrieve subset data
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
security: security:
- bearerAuth: [] - bearerAuth: []
- basicAuth: [] - basicAuth: []
...@@ -746,21 +758,20 @@ paths: ...@@ -746,21 +758,20 @@ paths:
$ref: "#/components/schemas/QueryPersistDto" $ref: "#/components/schemas/QueryPersistDto"
required: true required: true
responses: responses:
"202": "503":
description: Persisted subset description: Failed to communicate with database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/QueryDto" $ref: "#/components/schemas/ApiErrorDto"
"404": "202":
description: Failed to find database in metadata database or query in query description: Persisted subset
store of the data database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/QueryDto"
"503": "403":
description: Failed to communicate with database description: Not allowed to persist subset
content: content:
application/json: application/json:
schema: schema:
...@@ -771,8 +782,9 @@ paths: ...@@ -771,8 +782,9 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"403": "404":
description: Not allowed to persist subset description: Failed to find database in metadata database or query in query
store of the data database
content: content:
application/json: application/json:
schema: schema:
...@@ -823,26 +835,26 @@ paths: ...@@ -823,26 +835,26 @@ paths:
responses: responses:
"202": "202":
description: Imported dataset successfully description: Imported dataset successfully
"403": "503":
description: Import table dataset not allowed description: Failed to establish connection with the metadata service
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400": "404":
description: Dataset and/or query are malformed description: Failed to find table in metadata database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"503": "403":
description: Failed to establish connection with the metadata service description: Import table dataset not allowed
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404": "400":
description: Failed to find table in metadata database description: Dataset and/or query are malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -874,15 +886,15 @@ paths: ...@@ -874,15 +886,15 @@ paths:
schema: schema:
type: boolean type: boolean
responses: responses:
"404": "503":
description: Failed to find database in metadata database or query in query description: Failed to communicate with database
store of the data database
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"403": "404":
description: Not allowed to find subsets description: Failed to find database in metadata database or query in query
store of the data database
content: content:
application/json: application/json:
schema: schema:
...@@ -895,8 +907,8 @@ paths: ...@@ -895,8 +907,8 @@ paths:
type: array type: array
items: items:
$ref: "#/components/schemas/QueryDto" $ref: "#/components/schemas/QueryDto"
"503": "403":
description: Failed to communicate with database description: Not allowed to find subsets
content: content:
application/json: application/json:
schema: schema:
...@@ -945,15 +957,14 @@ paths: ...@@ -945,15 +957,14 @@ paths:
$ref: "#/components/schemas/ExecuteStatementDto" $ref: "#/components/schemas/ExecuteStatementDto"
required: true required: true
responses: responses:
"417": "201":
description: Failed to insert query into query store of data database description: Created subset
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" type: string
"404": "503":
description: Failed to find database in metadata database or query in query description: Failed to communicate with database
store of the data database
content: content:
application/json: application/json:
schema: schema:
...@@ -970,20 +981,21 @@ paths: ...@@ -970,20 +981,21 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"201": "404":
description: Created subset description: Failed to find database in metadata database or query in query
store of the data database
content: content:
application/json: application/json:
schema: schema:
type: string $ref: "#/components/schemas/ApiErrorDto"
"503": "400":
description: Failed to communicate with database description: Malformed select query
content: content:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"400": "417":
description: Malformed select query description: Failed to insert query into query store of data database
content: content:
application/json: application/json:
schema: schema:
...@@ -1020,12 +1032,6 @@ paths: ...@@ -1020,12 +1032,6 @@ paths:
type: string type: string
format: date-time format: date-time
responses: responses:
"404":
description: Failed to find view in metadata database or export dataset
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"503": "503":
description: Failed to establish connection with the metadata service description: Failed to establish connection with the metadata service
content: content:
...@@ -1038,6 +1044,12 @@ paths: ...@@ -1038,6 +1044,12 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find view in metadata database or export dataset
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"200": "200":
description: Exported view data description: Exported view data
content: content:
...@@ -1083,8 +1095,8 @@ paths: ...@@ -1083,8 +1095,8 @@ paths:
type: integer type: integer
format: int64 format: int64
responses: responses:
"404": "403":
description: Failed to find table history in data database description: Find table history not allowed
content: content:
application/json: application/json:
schema: schema:
...@@ -1095,8 +1107,8 @@ paths: ...@@ -1095,8 +1107,8 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"403": "404":
description: Find table history not allowed description: Failed to find table history in data database
content: content:
application/json: application/json:
schema: schema:
...@@ -1147,8 +1159,8 @@ paths: ...@@ -1147,8 +1159,8 @@ paths:
type: string type: string
format: date-time format: date-time
responses: responses:
"403": "400":
description: Export table data not allowed description: Request pagination or table data select query is malformed
content: content:
application/json: application/json:
schema: schema:
...@@ -1159,12 +1171,6 @@ paths: ...@@ -1159,12 +1171,6 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"404":
description: Failed to find table in metadata database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"200": "200":
description: Exported table data description: Exported table data
content: content:
...@@ -1172,8 +1178,14 @@ paths: ...@@ -1172,8 +1178,14 @@ paths:
schema: schema:
type: string type: string
format: binary format: binary
"400": "404":
description: Request pagination or table data select query is malformed description: Failed to find table in metadata database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"403":
description: Export table data not allowed
content: content:
application/json: application/json:
schema: schema:
...@@ -1217,9 +1229,8 @@ paths: ...@@ -1217,9 +1229,8 @@ paths:
type: string type: string
format: date-time format: date-time
responses: responses:
"404": "503":
description: Failed to find database in metadata database or query in query description: Failed to communicate with database
store of the data database
content: content:
application/json: application/json:
schema: schema:
...@@ -1236,12 +1247,6 @@ paths: ...@@ -1236,12 +1247,6 @@ paths:
application/json: application/json:
schema: schema:
$ref: "#/components/schemas/ApiErrorDto" $ref: "#/components/schemas/ApiErrorDto"
"503":
description: Failed to communicate with database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"200": "200":
description: Found subset description: Found subset
content: content:
...@@ -1249,6 +1254,13 @@ paths: ...@@ -1249,6 +1254,13 @@ paths:
schema: schema:
$ref: "#/components/schemas/QueryDto" $ref: "#/components/schemas/QueryDto"
text/csv: {} text/csv: {}
"404":
description: Failed to find database in metadata database or query in query
store of the data database
content:
application/json:
schema:
$ref: "#/components/schemas/ApiErrorDto"
"400": "400":
description: Malformed select query description: Malformed select query
content: content:
......
This diff is collapsed.
This diff is collapsed.
package at.tuwien.endpoints; package at.tuwien.endpoints;
import at.tuwien.ExportResourceDto; import at.tuwien.ExportResourceDto;
import at.tuwien.api.database.CreateViewDto;
import at.tuwien.api.database.DatabaseDto; import at.tuwien.api.database.DatabaseDto;
import at.tuwien.api.database.ViewColumnDto; import at.tuwien.api.database.ViewColumnDto;
import at.tuwien.api.database.ViewDto; import at.tuwien.api.database.ViewDto;
...@@ -163,8 +164,7 @@ public class SubsetEndpoint extends RestEndpoint { ...@@ -163,8 +164,7 @@ public class SubsetEndpoint extends RestEndpoint {
Principal principal) Principal principal)
throws DatabaseUnavailableException, DatabaseNotFoundException, RemoteUnavailableException, throws DatabaseUnavailableException, DatabaseNotFoundException, RemoteUnavailableException,
QueryNotFoundException, FormatNotAvailableException, StorageUnavailableException, UserNotFoundException, QueryNotFoundException, FormatNotAvailableException, StorageUnavailableException, UserNotFoundException,
MetadataServiceException, TableNotFoundException, ViewMalformedException, QueryMalformedException, MetadataServiceException, TableNotFoundException, QueryMalformedException, NotAllowedException {
NotAllowedException {
log.debug("endpoint find subset in database, databaseId={}, subsetId={}, accept={}, timestamp={}", databaseId, log.debug("endpoint find subset in database, databaseId={}, subsetId={}, accept={}, timestamp={}", databaseId,
subsetId, accept, timestamp); subsetId, accept, timestamp);
final DatabaseDto database = credentialService.getDatabase(databaseId); final DatabaseDto database = credentialService.getDatabase(databaseId);
...@@ -341,7 +341,7 @@ public class SubsetEndpoint extends RestEndpoint { ...@@ -341,7 +341,7 @@ public class SubsetEndpoint extends RestEndpoint {
@RequestParam(required = false) Long size) @RequestParam(required = false) Long size)
throws PaginationException, DatabaseNotFoundException, RemoteUnavailableException, NotAllowedException, throws PaginationException, DatabaseNotFoundException, RemoteUnavailableException, NotAllowedException,
QueryNotFoundException, DatabaseUnavailableException, TableMalformedException, QueryMalformedException, QueryNotFoundException, DatabaseUnavailableException, TableMalformedException, QueryMalformedException,
UserNotFoundException, MetadataServiceException, TableNotFoundException, ViewNotFoundException { UserNotFoundException, MetadataServiceException, TableNotFoundException, ViewNotFoundException, ViewMalformedException {
log.debug("endpoint get subset data, databaseId={}, subsetId={}, principal.name={} page={}, size={}", log.debug("endpoint get subset data, databaseId={}, subsetId={}, principal.name={} page={}, size={}",
databaseId, subsetId, principal != null ? principal.getName() : null, page, size); databaseId, subsetId, principal != null ? principal.getName() : null, page, size);
endpointValidator.validateDataParams(page, size); endpointValidator.validateDataParams(page, size);
...@@ -383,6 +383,12 @@ public class SubsetEndpoint extends RestEndpoint { ...@@ -383,6 +383,12 @@ public class SubsetEndpoint extends RestEndpoint {
final Dataset<Row> dataset = subsetService.getData(database, query, timestamp, page, size, null, null); final Dataset<Row> dataset = subsetService.getData(database, query, timestamp, page, size, null, null);
metricsService.countSubsetGetData(databaseId, subsetId); metricsService.countSubsetGetData(databaseId, subsetId);
final String viewName = metadataMapper.queryDtoToViewName(subset); final String viewName = metadataMapper.queryDtoToViewName(subset);
databaseService.createView(database, CreateViewDto.builder()
.name(viewName)
.isPublic(false)
.isSchemaPublic(false)
.query(query)
.build());
final ViewDto view = databaseService.inspectView(database, viewName); final ViewDto view = databaseService.inspectView(database, viewName);
headers.set("Access-Control-Expose-Headers", "X-Id X-Headers"); headers.set("Access-Control-Expose-Headers", "X-Id X-Headers");
headers.set("X-Headers", String.join(",", view.getColumns().stream().map(ViewColumnDto::getInternalName).toList())); headers.set("X-Headers", String.join(",", view.getColumns().stream().map(ViewColumnDto::getInternalName).toList()));
......
...@@ -6,7 +6,7 @@ import at.tuwien.api.database.DatabaseDto; ...@@ -6,7 +6,7 @@ import at.tuwien.api.database.DatabaseDto;
import at.tuwien.config.QueryConfig; import at.tuwien.config.QueryConfig;
import at.tuwien.endpoints.RestEndpoint; import at.tuwien.endpoints.RestEndpoint;
import at.tuwien.exception.*; import at.tuwien.exception.*;
import at.tuwien.gateway.MetadataServiceGateway; import at.tuwien.service.CredentialService;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -24,12 +24,12 @@ import java.util.regex.Pattern; ...@@ -24,12 +24,12 @@ import java.util.regex.Pattern;
public class EndpointValidator extends RestEndpoint { public class EndpointValidator extends RestEndpoint {
private final QueryConfig queryConfig; private final QueryConfig queryConfig;
private final MetadataServiceGateway metadataServiceGateway; private final CredentialService credentialService;
@Autowired @Autowired
public EndpointValidator(QueryConfig queryConfig, MetadataServiceGateway metadataServiceGateway) { public EndpointValidator(QueryConfig queryConfig, CredentialService credentialService) {
this.queryConfig = queryConfig; this.queryConfig = queryConfig;
this.metadataServiceGateway = metadataServiceGateway; this.credentialService = credentialService;
} }
public void validateDataParams(Long page, Long size) throws PaginationException { public void validateDataParams(Long page, Long size) throws PaginationException {
...@@ -90,7 +90,7 @@ public class EndpointValidator extends RestEndpoint { ...@@ -90,7 +90,7 @@ public class EndpointValidator extends RestEndpoint {
if (isSystem(principal)) { if (isSystem(principal)) {
return; return;
} }
final DatabaseAccessDto access = metadataServiceGateway.getAccess(database.getId(), getId(principal)); final DatabaseAccessDto access = credentialService.getAccess(database.getId(), getId(principal));
log.trace("found access: {}", access); log.trace("found access: {}", access);
if (writeAccessOnly && !(access.getType().equals(AccessTypeDto.WRITE_OWN) || access.getType().equals(AccessTypeDto.WRITE_ALL))) { if (writeAccessOnly && !(access.getType().equals(AccessTypeDto.WRITE_OWN) || access.getType().equals(AccessTypeDto.WRITE_ALL))) {
log.error("Access not allowed: no write access"); log.error("Access not allowed: no write access");
......
...@@ -51,7 +51,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -51,7 +51,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_4_ID)) when(credentialService.getUser(USER_4_ID))
.thenReturn(USER_4_DTO); .thenReturn(USER_4_DTO);
...@@ -68,7 +68,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -68,7 +68,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_1_ID)) when(credentialService.getUser(USER_1_ID))
.thenReturn(USER_1_DTO); .thenReturn(USER_1_DTO);
...@@ -85,12 +85,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -85,12 +85,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_4_ID)) when(credentialService.getUser(USER_4_ID))
.thenReturn(USER_4_DTO); .thenReturn(USER_4_DTO);
doThrow(SQLException.class) doThrow(SQLException.class)
.when(accessService) .when(accessService)
.create(DATABASE_1_DTO, USER_4_DTO, AccessTypeDto.READ); .create(DATABASE_1_PRIVILEGED_DTO, USER_4_DTO, AccessTypeDto.READ);
/* test */ /* test */
assertThrows(DatabaseUnavailableException.class, () -> { assertThrows(DatabaseUnavailableException.class, () -> {
...@@ -121,7 +121,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -121,7 +121,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(UserNotFoundException.class) doThrow(UserNotFoundException.class)
.when(credentialService) .when(credentialService)
.getUser(USER_4_ID); .getUser(USER_4_ID);
...@@ -149,7 +149,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -149,7 +149,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_1_ID)) when(credentialService.getUser(USER_1_ID))
.thenReturn(USER_1_DTO); .thenReturn(USER_1_DTO);
...@@ -166,12 +166,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -166,12 +166,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_1_ID)) when(credentialService.getUser(USER_1_ID))
.thenReturn(USER_1_DTO); .thenReturn(USER_1_DTO);
doThrow(SQLException.class) doThrow(SQLException.class)
.when(accessService) .when(accessService)
.update(DATABASE_1_DTO, USER_1_DTO, AccessTypeDto.READ); .update(DATABASE_1_PRIVILEGED_DTO, USER_1_DTO, AccessTypeDto.READ);
/* test */ /* test */
assertThrows(DatabaseUnavailableException.class, () -> { assertThrows(DatabaseUnavailableException.class, () -> {
...@@ -186,7 +186,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -186,7 +186,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_4_ID)) when(credentialService.getUser(USER_4_ID))
.thenReturn(USER_4_DTO); .thenReturn(USER_4_DTO);
...@@ -229,7 +229,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -229,7 +229,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(UserNotFoundException.class) doThrow(UserNotFoundException.class)
.when(credentialService) .when(credentialService)
.getUser(USER_1_ID); .getUser(USER_1_ID);
...@@ -248,7 +248,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -248,7 +248,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_1_ID)) when(credentialService.getUser(USER_1_ID))
.thenReturn(USER_1_DTO); .thenReturn(USER_1_DTO);
doNothing() doNothing()
...@@ -268,7 +268,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -268,7 +268,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_4_ID)) when(credentialService.getUser(USER_4_ID))
.thenReturn(USER_4_DTO); .thenReturn(USER_4_DTO);
...@@ -311,7 +311,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -311,7 +311,7 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(UserNotFoundException.class) doThrow(UserNotFoundException.class)
.when(credentialService) .when(credentialService)
.getUser(USER_1_ID); .getUser(USER_1_ID);
...@@ -329,12 +329,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest { ...@@ -329,12 +329,12 @@ public class AccessEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
when(credentialService.getUser(USER_1_ID)) when(credentialService.getUser(USER_1_ID))
.thenReturn(USER_1_DTO); .thenReturn(USER_1_DTO);
doThrow(SQLException.class) doThrow(SQLException.class)
.when(accessService) .when(accessService)
.delete(DATABASE_1_DTO, USER_1_DTO); .delete(DATABASE_1_PRIVILEGED_DTO, USER_1_DTO);
/* test */ /* test */
assertThrows(DatabaseUnavailableException.class, () -> { assertThrows(DatabaseUnavailableException.class, () -> {
......
...@@ -65,13 +65,13 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -65,13 +65,13 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
when(credentialService.getContainer(CONTAINER_1_ID)) when(credentialService.getContainer(CONTAINER_1_ID))
.thenReturn(CONTAINER_1_DTO); .thenReturn(CONTAINER_1_DTO);
when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL)) when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doNothing() doNothing()
.when(containerService) .when(containerService)
.createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME); .createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME);
doNothing() doNothing()
.when(accessService) .when(accessService)
.create(eq(DATABASE_1_DTO), any(UserDto.class), any(AccessTypeDto.class)); .create(eq(DATABASE_1_PRIVILEGED_DTO), any(UserDto.class), any(AccessTypeDto.class));
/* test */ /* test */
final ResponseEntity<DatabaseDto> response = databaseEndpoint.create(DATABASE_1_CREATE_INTERNAL); final ResponseEntity<DatabaseDto> response = databaseEndpoint.create(DATABASE_1_CREATE_INTERNAL);
...@@ -87,13 +87,13 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -87,13 +87,13 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
when(credentialService.getContainer(CONTAINER_1_ID)) when(credentialService.getContainer(CONTAINER_1_ID))
.thenReturn(CONTAINER_1_DTO); .thenReturn(CONTAINER_1_DTO);
when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL)) when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doNothing() doNothing()
.when(containerService) .when(containerService)
.createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME); .createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME);
doNothing() doNothing()
.when(accessService) .when(accessService)
.create(eq(DATABASE_1_DTO), any(UserDto.class), any(AccessTypeDto.class)); .create(eq(DATABASE_1_PRIVILEGED_DTO), any(UserDto.class), any(AccessTypeDto.class));
/* test */ /* test */
assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> {
...@@ -145,7 +145,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -145,7 +145,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
.when(credentialService) .when(credentialService)
.getContainer(CONTAINER_1_ID); .getContainer(CONTAINER_1_ID);
when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL)) when(containerService.createDatabase(CONTAINER_1_DTO, DATABASE_1_CREATE_INTERNAL))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(QueryStoreCreateException.class) doThrow(QueryStoreCreateException.class)
.when(containerService) .when(containerService)
.createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME); .createQueryStore(CONTAINER_1_DTO, DATABASE_1_INTERNALNAME);
...@@ -163,7 +163,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -163,7 +163,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
/* test */ /* test */
databaseEndpoint.update(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO); databaseEndpoint.update(DATABASE_1_ID, USER_1_UPDATE_PASSWORD_DTO);
...@@ -176,10 +176,10 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -176,10 +176,10 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(SQLException.class) doThrow(SQLException.class)
.when(databaseService) .when(databaseService)
.update(DATABASE_1_DTO, USER_1_UPDATE_PASSWORD_DTO); .update(DATABASE_1_PRIVILEGED_DTO, USER_1_UPDATE_PASSWORD_DTO);
/* test */ /* test */
assertThrows(DatabaseUnavailableException.class, () -> { assertThrows(DatabaseUnavailableException.class, () -> {
...@@ -193,7 +193,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -193,7 +193,7 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
/* test */ /* test */
assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> { assertThrows(org.springframework.security.access.AccessDeniedException.class, () -> {
...@@ -224,10 +224,10 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest { ...@@ -224,10 +224,10 @@ public class DatabaseEndpointUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(credentialService.getDatabase(DATABASE_1_ID)) when(credentialService.getDatabase(DATABASE_1_ID))
.thenReturn(DATABASE_1_DTO); .thenReturn(DATABASE_1_PRIVILEGED_DTO);
doThrow(DatabaseMalformedException.class) doThrow(DatabaseMalformedException.class)
.when(databaseService) .when(databaseService)
.update(DATABASE_1_DTO, USER_1_UPDATE_PASSWORD_DTO); .update(DATABASE_1_PRIVILEGED_DTO, USER_1_UPDATE_PASSWORD_DTO);
/* test */ /* test */
assertThrows(DatabaseMalformedException.class, () -> { assertThrows(DatabaseMalformedException.class, () -> {
......
...@@ -59,7 +59,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -59,7 +59,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class))) when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class)))
.thenReturn(ResponseEntity.status(HttpStatus.OK) .thenReturn(ResponseEntity.status(HttpStatus.OK)
.headers(headers) .headers(headers)
.body(TABLE_1_DTO)); .body(TABLE_1_PRIVILEGED_DTO));
/* test */ /* test */
final TableDto response = metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID); final TableDto response = metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID);
...@@ -105,7 +105,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -105,7 +105,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class))) when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class)))
.thenReturn(ResponseEntity.status(HttpStatus.NO_CONTENT) .thenReturn(ResponseEntity.status(HttpStatus.NO_CONTENT)
.body(TABLE_1_DTO)); .body(TABLE_1_PRIVILEGED_DTO));
/* test */ /* test */
assertThrows(MetadataServiceException.class, () -> { assertThrows(MetadataServiceException.class, () -> {
...@@ -115,7 +115,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -115,7 +115,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
@Test @Test
public void getTableById_headerMissing_fails() { public void getTableById_headerMissing_fails() {
final List<String> customHeaders = List.of("X-Type", "X-Host", "X-Port", "X-Username", "X-Password", "X-Database", "X-Sidecar-Host", "X-Sidecar-Port"); final List<String> customHeaders = List.of("X-Username", "X-Password");
for (int i = 0; i < customHeaders.size(); i++) { for (int i = 0; i < customHeaders.size(); i++) {
final HttpHeaders headers = new HttpHeaders(); final HttpHeaders headers = new HttpHeaders();
...@@ -126,7 +126,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -126,7 +126,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class))) when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(TableDto.class)))
.thenReturn(ResponseEntity.status(HttpStatus.OK) .thenReturn(ResponseEntity.status(HttpStatus.OK)
.headers(headers) .headers(headers)
.body(TABLE_1_DTO)); .body(TABLE_1_PRIVILEGED_DTO));
/* test */ /* test */
assertThrows(MetadataServiceException.class, () -> { assertThrows(MetadataServiceException.class, () -> {
metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID); metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID);
...@@ -163,7 +163,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -163,7 +163,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(DatabaseDto.class))) when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), eq(HttpEntity.EMPTY), eq(DatabaseDto.class)))
.thenReturn(ResponseEntity.ok() .thenReturn(ResponseEntity.ok()
.headers(headers) .headers(headers)
.body(DATABASE_1_DTO)); .body(DATABASE_1_PRIVILEGED_DTO));
/* test */ /* test */
final DatabaseDto response = metadataServiceGateway.getDatabaseById(DATABASE_1_ID); final DatabaseDto response = metadataServiceGateway.getDatabaseById(DATABASE_1_ID);
...@@ -359,7 +359,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest { ...@@ -359,7 +359,7 @@ public class MetadataServiceGatewayUnitTest extends AbstractUnitTest {
when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), eq(ViewDto.class))) when(internalRestTemplate.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), eq(ViewDto.class)))
.thenReturn(ResponseEntity.ok() .thenReturn(ResponseEntity.ok()
.headers(headers) .headers(headers)
.body(VIEW_1_DTO)); .body(VIEW_1_PRIVILEGED_DTO));
/* test */ /* test */
final ViewDto response = metadataServiceGateway.getViewById(CONTAINER_1_ID, VIEW_1_ID); final ViewDto response = metadataServiceGateway.getViewById(CONTAINER_1_ID, VIEW_1_ID);
......
...@@ -5,7 +5,7 @@ import at.tuwien.config.MariaDbContainerConfig; ...@@ -5,7 +5,7 @@ import at.tuwien.config.MariaDbContainerConfig;
import at.tuwien.exception.MetadataServiceException; import at.tuwien.exception.MetadataServiceException;
import at.tuwien.exception.RemoteUnavailableException; import at.tuwien.exception.RemoteUnavailableException;
import at.tuwien.exception.TableNotFoundException; import at.tuwien.exception.TableNotFoundException;
import at.tuwien.gateway.MetadataServiceGateway; import at.tuwien.service.CredentialService;
import at.tuwien.test.AbstractUnitTest; import at.tuwien.test.AbstractUnitTest;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -42,13 +42,13 @@ import static org.mockito.Mockito.when; ...@@ -42,13 +42,13 @@ import static org.mockito.Mockito.when;
public class DefaultListenerIntegrationTest extends AbstractUnitTest { public class DefaultListenerIntegrationTest extends AbstractUnitTest {
@MockBean @MockBean
private MetadataServiceGateway metadataServiceGateway; private CredentialService credentialService;
@Autowired @Autowired
private DefaultListener defaultListener; private DefaultListener defaultListener;
@Container @Container
private static RabbitMQContainer rabbitContainer = new RabbitMQContainer("rabbitmq:3.10"); private static RabbitMQContainer rabbitContainer = new RabbitMQContainer(RABBITMQ_IMAGE);
@Container @Container
private static MariaDBContainer<?> mariaDBContainer = MariaDbContainerConfig.getContainer(); private static MariaDBContainer<?> mariaDBContainer = MariaDbContainerConfig.getContainer();
...@@ -67,8 +67,8 @@ public class DefaultListenerIntegrationTest extends AbstractUnitTest { ...@@ -67,8 +67,8 @@ public class DefaultListenerIntegrationTest extends AbstractUnitTest {
final Message request = buildMessage("dbrepo." + DATABASE_1_ID + "." + TABLE_1_ID, "{\"id\":4,\"date\":\"2023-10-03\",\"mintemp\":15.0,\"rainfall\":0.2}", new HashMap<>()); final Message request = buildMessage("dbrepo." + DATABASE_1_ID + "." + TABLE_1_ID, "{\"id\":4,\"date\":\"2023-10-03\",\"mintemp\":15.0,\"rainfall\":0.2}", new HashMap<>());
/* mock */ /* mock */
when(metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID)) when(credentialService.getTable(DATABASE_1_ID, TABLE_1_ID))
.thenReturn(TABLE_1_DTO); .thenReturn(TABLE_1_PRIVILEGED_DTO);
/* test */ /* test */
defaultListener.onMessage(request); defaultListener.onMessage(request);
...@@ -83,8 +83,8 @@ public class DefaultListenerIntegrationTest extends AbstractUnitTest { ...@@ -83,8 +83,8 @@ public class DefaultListenerIntegrationTest extends AbstractUnitTest {
/* mock */ /* mock */
doThrow(TableNotFoundException.class) doThrow(TableNotFoundException.class)
.when(metadataServiceGateway) .when(credentialService)
.getTableById(DATABASE_1_ID, TABLE_1_ID); .getTable(DATABASE_1_ID, TABLE_1_ID);
/* test */ /* test */
defaultListener.onMessage(request); defaultListener.onMessage(request);
......
...@@ -5,7 +5,7 @@ import at.tuwien.config.MariaDbContainerConfig; ...@@ -5,7 +5,7 @@ import at.tuwien.config.MariaDbContainerConfig;
import at.tuwien.exception.MetadataServiceException; import at.tuwien.exception.MetadataServiceException;
import at.tuwien.exception.RemoteUnavailableException; import at.tuwien.exception.RemoteUnavailableException;
import at.tuwien.exception.TableNotFoundException; import at.tuwien.exception.TableNotFoundException;
import at.tuwien.gateway.MetadataServiceGateway; import at.tuwien.service.CredentialService;
import at.tuwien.test.AbstractUnitTest; import at.tuwien.test.AbstractUnitTest;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -38,7 +38,7 @@ import static org.mockito.Mockito.when; ...@@ -38,7 +38,7 @@ import static org.mockito.Mockito.when;
public class DefaultListenerUnitTest extends AbstractUnitTest { public class DefaultListenerUnitTest extends AbstractUnitTest {
@MockBean @MockBean
private MetadataServiceGateway metadataServiceGateway; private CredentialService credentialService;
@Autowired @Autowired
private DefaultListener defaultListener; private DefaultListener defaultListener;
...@@ -54,7 +54,7 @@ public class DefaultListenerUnitTest extends AbstractUnitTest { ...@@ -54,7 +54,7 @@ public class DefaultListenerUnitTest extends AbstractUnitTest {
genesis(); genesis();
/* metadata database */ /* metadata database */
MariaDbConfig.dropAllDatabases(CONTAINER_1_PRIVILEGED_DTO); MariaDbConfig.dropAllDatabases(CONTAINER_1_PRIVILEGED_DTO);
MariaDbConfig.createInitDatabase(CONTAINER_1_PRIVILEGED_DTO, DATABASE_1_DTO); MariaDbConfig.createInitDatabase(CONTAINER_1_PRIVILEGED_DTO, DATABASE_1_PRIVILEGED_DTO);
} }
@Test @Test
...@@ -81,8 +81,8 @@ public class DefaultListenerUnitTest extends AbstractUnitTest { ...@@ -81,8 +81,8 @@ public class DefaultListenerUnitTest extends AbstractUnitTest {
final Message request = buildMessage("dbrepo.1.1", "{,}", new HashMap<>()); final Message request = buildMessage("dbrepo.1.1", "{,}", new HashMap<>());
/* mock */ /* mock */
when(metadataServiceGateway.getTableById(DATABASE_1_ID, TABLE_1_ID)) when(credentialService.getTable(DATABASE_1_ID, TABLE_1_ID))
.thenReturn(TABLE_1_DTO); .thenReturn(TABLE_1_PRIVILEGED_DTO);
/* test */ /* test */
defaultListener.onMessage(request); defaultListener.onMessage(request);
...@@ -96,8 +96,8 @@ public class DefaultListenerUnitTest extends AbstractUnitTest { ...@@ -96,8 +96,8 @@ public class DefaultListenerUnitTest extends AbstractUnitTest {
/* mock */ /* mock */
doThrow(TableNotFoundException.class) doThrow(TableNotFoundException.class)
.when(metadataServiceGateway) .when(credentialService)
.getTableById(DATABASE_1_ID, TABLE_1_ID); .getTable(DATABASE_1_ID, TABLE_1_ID);
/* test */ /* test */
defaultListener.onMessage(request); defaultListener.onMessage(request);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment