|
| 1 | +/* |
| 2 | + * Copyright 2013 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.springframework.data.elasticsearch.repository.support; |
| 17 | + |
| 18 | +import org.junit.Before; |
| 19 | +import org.junit.Test; |
| 20 | +import org.junit.runner.RunWith; |
| 21 | +import org.mockito.Mock; |
| 22 | +import org.mockito.runners.MockitoJUnitRunner; |
| 23 | +import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; |
| 24 | +import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty; |
| 25 | +import org.springframework.data.mapping.context.MappingContext; |
| 26 | + |
| 27 | +import static org.mockito.Mockito.doReturn; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Florian Hopf |
| 31 | + */ |
| 32 | +@RunWith(MockitoJUnitRunner.class) |
| 33 | +public class ElasticsearchEntityInformationCreatorImplTest { |
| 34 | + |
| 35 | + @Mock |
| 36 | + private MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext; |
| 37 | + @Mock |
| 38 | + private ElasticsearchPersistentEntity<String> persistentEntity; |
| 39 | + private ElasticsearchEntityInformationCreatorImpl entityInfoCreator; |
| 40 | + |
| 41 | + @Before |
| 42 | + public void before() { |
| 43 | + entityInfoCreator = new ElasticsearchEntityInformationCreatorImpl(mappingContext); |
| 44 | + } |
| 45 | + |
| 46 | + @Test(expected = IllegalArgumentException.class) |
| 47 | + public void shouldThrowIllegalArgumentExceptionOnMissingEntity() { |
| 48 | + entityInfoCreator.getEntityInformation(String.class); |
| 49 | + } |
| 50 | + |
| 51 | + @Test(expected = IllegalArgumentException.class) |
| 52 | + public void shouldThrowIllegalArgumentExceptionOnMissingIdAnnotation() { |
| 53 | + doReturn(persistentEntity).when(mappingContext).getPersistentEntity(String.class); |
| 54 | + doReturn(String.class).when(persistentEntity).getType(); |
| 55 | + doReturn(null).when(persistentEntity).getIdProperty(); |
| 56 | + entityInfoCreator.getEntityInformation(String.class); |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments