-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.x] Allow to override the default mappings provided by DsColumnMapping
#186
Changes from 13 commits
892dbb6
082e1a9
fb465f3
30200c1
172a6b8
75c9bdb
11b1803
26c28b4
156d20b
d00b436
07e697f
91ad656
a7dcee9
ed9eab6
70b8108
377c277
634e46f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2023, TeamDev. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* Redistribution and use in source and/or binary forms, with or without | ||
* modification, must retain the above copyright notice and the following | ||
* disclaimer. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
package io.spine.server.storage.datastore; | ||
|
||
import com.google.cloud.datastore.Key; | ||
import com.google.protobuf.Timestamp; | ||
import io.spine.core.Version; | ||
import io.spine.server.ContextSpec; | ||
import io.spine.server.projection.ProjectionStorage; | ||
import io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.CustomMapping; | ||
import io.spine.test.datastore.College; | ||
import io.spine.test.datastore.CollegeId; | ||
import io.spine.testing.server.storage.datastore.TestDatastoreStorageFactory; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
import static io.spine.server.storage.datastore.RecordId.ofEntityId; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.COLLEGE_CLS; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.COLLEGE_KIND; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.clearAdmission; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.futureFromNow; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.newCollege; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.newId; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.someVersion; | ||
import static io.spine.server.storage.datastore.given.DsProjectionColumnsTestEnv.writeAndReadDeadline; | ||
import static io.spine.server.storage.datastore.given.TestEnvironment.singleTenantSpec; | ||
import static io.spine.testing.server.storage.datastore.TestDatastoreStorageFactory.local; | ||
|
||
@DisplayName("When dealing with `Projection` columns, `DsProjectionStorage` should") | ||
final class DsProjectionColumnsTest { | ||
|
||
private static final TestDatastoreStorageFactory datastoreFactory = local(new CustomMapping()); | ||
|
||
@Test | ||
@DisplayName( | ||
"allow clearing the column values if they get Proto's default values, " + | ||
"by having a custom column mapping " + | ||
"returning Datastore's `null` for respective values") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would simplify this name to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplified a bit. But still, we need to be a bit more precise here, as the idea of the test is to check the configuration with the specific column mapping. |
||
void clearTimestampColumns() { | ||
ContextSpec spec = singleTenantSpec(); | ||
ProjectionStorage<CollegeId> storage = | ||
datastoreFactory.createProjectionStorage(spec, COLLEGE_CLS); | ||
DatastoreWrapper datastore = datastoreFactory.createDatastoreWrapper(false); | ||
|
||
CollegeId id = newId(); | ||
Key key = datastore.keyFor(COLLEGE_KIND, ofEntityId(id)); | ||
Version version = someVersion(); | ||
|
||
Timestamp admissionDeadline = futureFromNow(); | ||
College college = newCollege(id, admissionDeadline); | ||
|
||
com.google.cloud.Timestamp storedDeadline = | ||
writeAndReadDeadline(college, version, storage, datastore, key); | ||
assertThat(storedDeadline).isNotNull(); | ||
|
||
College collegeNoAdmission = clearAdmission(college); | ||
com.google.cloud.Timestamp presumablyEmptyDeadline = | ||
writeAndReadDeadline(collegeNoAdmission, version, storage, datastore, key); | ||
assertThat(presumablyEmptyDeadline) | ||
.isNull(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would move
"ProtoTimestampGetSecondsGetNano"
to a new line.And the same with the suppression below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.