|
| 1 | +/* |
| 2 | + * DISCLAIMER |
| 3 | + * |
| 4 | + * Copyright 2018 ArangoDB GmbH, Cologne, Germany |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * Copyright holder is ArangoDB GmbH, Cologne, Germany |
| 19 | + */ |
| 20 | + |
| 21 | +package com.arangodb.springframework.core.mapping; |
| 22 | + |
| 23 | +import com.arangodb.springframework.AbstractArangoTest; |
| 24 | +import com.arangodb.springframework.annotation.Ref; |
| 25 | +import com.arangodb.springframework.core.convert.resolver.LazyLoadingProxy; |
| 26 | +import com.arangodb.springframework.core.mapping.testdata.BasicTestEntity; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | + |
| 29 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 30 | +import static org.hamcrest.Matchers.*; |
| 31 | + |
| 32 | +public class LazyLoadingProxyTest extends AbstractArangoTest { |
| 33 | + |
| 34 | + public static class SingleReferenceLazyTestEntity extends BasicTestEntity { |
| 35 | + @Ref(lazy = true) |
| 36 | + private BasicTestEntity entity; |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void isResolved() { |
| 41 | + final BasicTestEntity e1 = new BasicTestEntity(); |
| 42 | + template.insert(e1); |
| 43 | + final SingleReferenceLazyTestEntity e0 = new SingleReferenceLazyTestEntity(); |
| 44 | + e0.entity = e1; |
| 45 | + template.insert(e0); |
| 46 | + final SingleReferenceLazyTestEntity document = template.find(e0.id, SingleReferenceLazyTestEntity.class).get(); |
| 47 | + assertThat(document, is(notNullValue())); |
| 48 | + assertThat(document.entity, is(notNullValue())); |
| 49 | + assertThat(document.entity, instanceOf(LazyLoadingProxy.class)); |
| 50 | + assertThat(document.entity, instanceOf(BasicTestEntity.class)); |
| 51 | + assertThat(((LazyLoadingProxy) document.entity).isResolved(), is(false)); |
| 52 | + assertThat(document.entity.getId(), is(e1.getId())); |
| 53 | + assertThat(((LazyLoadingProxy) document.entity).isResolved(), is(true)); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments