|
@@ -0,0 +1,95 @@
|
|
|
+package com.use.cloud.mall.floor;
|
|
|
+
|
|
|
+import com.use.cloud.mall.floor.domain.Floor;
|
|
|
+import com.use.cloud.mall.floor.domain.Item;
|
|
|
+import com.use.cloud.mall.floor.repository.FloorRepository;
|
|
|
+import org.junit.Before;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.mongodb.core.MongoOperations;
|
|
|
+import org.springframework.test.context.ContextConfiguration;
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Random;
|
|
|
+
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
|
+
|
|
|
+
|
|
|
+ * Created by yangck on 2017/2/27.
|
|
|
+ */
|
|
|
+
|
|
|
+@ContextConfiguration(classes = FloorApplication.class)
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)*/
|
|
|
+public class FloorApplicationTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FloorRepository floorRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MongoOperations operations;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void cleanup() {
|
|
|
+ floorRepository.deleteAll();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testMongoRepository() {
|
|
|
+ assertEquals(0, floorRepository.count());
|
|
|
+
|
|
|
+ Floor floor1 = floorRepository.save(createFloor("手机", "home", 1));
|
|
|
+ Floor floor2 = floorRepository.save(createFloor("家电", "home", 2));
|
|
|
+ Floor floor3 = floorRepository.save(createFloor("车载", "home", 3));
|
|
|
+ Floor floor4 = floorRepository.save(createFloor("消费电子", "home", 4));
|
|
|
+ Floor floor5 = floorRepository.save(createFloor("材料加工", "home", 5));
|
|
|
+
|
|
|
+ assertEquals(5, floorRepository.count());
|
|
|
+ Floor floor1_Found = floorRepository.findByUsedForAndFloorNumber("home", 1l);
|
|
|
+ assertEquals("手机", floor1_Found.getName());
|
|
|
+ assertEquals(8, floor1_Found.getItems().size());
|
|
|
+ System.out.println(floor1_Found);
|
|
|
+
|
|
|
+ System.out.println("--------yangck--------floor1_Found值=" + floor1_Found + "," + "当前类=FloorApplicationTest.testMongoRepository()");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private Floor createFloor(String name, String usedFor, Integer orderNumber) {
|
|
|
+ Floor floor = new Floor();
|
|
|
+ floor.setUsedFor(usedFor);
|
|
|
+ floor.setName(name);
|
|
|
+ floor.setFloorNumber(orderNumber);
|
|
|
+ Item item1 = createItem("", "", 1, "tiny");
|
|
|
+ Item item2 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 2, "large");
|
|
|
+ Item item3 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 3, "medium");
|
|
|
+ Item item4 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 4, "small");
|
|
|
+ Item item5 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 5, "small");
|
|
|
+ Item item6 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 6, "medium");
|
|
|
+ Item item7 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 7, "small");
|
|
|
+ Item item8 = createItem("商品名称", "商品介绍、商品介绍、商品介绍、商品介绍、商品介绍", 8, "small");
|
|
|
+ floor.setItems(Arrays.asList(item1, item2, item3, item4, item5, item6, item7, item8));
|
|
|
+
|
|
|
+ return floor;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Item createItem(String name, String body, Integer orderNumber, String size) {
|
|
|
+ Item item = new Item();
|
|
|
+ item.setName(name);
|
|
|
+ item.setBody(body);
|
|
|
+ item.setPictureUrl(getRandomUrl());
|
|
|
+ item.setHrefUrl("http://www.ubtob.com/");
|
|
|
+ item.setOrderNumber(orderNumber);
|
|
|
+ item.setSize(size);
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Random random = new Random();
|
|
|
+
|
|
|
+ private String getRandomUrl() {
|
|
|
+ String[] urls = new String[] {"http://www.ubtob.com/static/img/about.png", "http://www.ubtob.com/static/img/carousel/header-06.jpg", "http://www.ubtob.com/static/img/carousel/header-02.jpg", "http://www.ubtob.com/static/img/carousel/header-07.jpg", "http://www.ubtob.com/static/img/carousel/header-04.jpg", "http://www.ubtob.com/static/img/carousel/header-05.jpg", "http://www.ubtob.com/static/img/about_saas/ad_01.jpg", "http://www.ubtob.com/static/img/about_saas/ad_01.jpg"};
|
|
|
+ int index = random.nextInt(urls.length);
|
|
|
+ return urls[index];
|
|
|
+ }*/
|
|
|
+}
|