Commit a4dcfadd authored by shiyu's avatar shiyu

测试类

parent 250d7146
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.service.CategoryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class CategoryServiceImplTest {
@Autowired
CategoryService categoryService;
@Test
public void getSubCategory() {
categoryService.getSubCategory(1001025);
}
}
\ No newline at end of file
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.job.SynCoinJob;
import com.wwdz.ch.admin.service.AdminGoodsService;
import com.wwdz.ch.admin.service.ItemService;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.MediaTypeEnum;
import com.wwdz.ch.core.storage.QiniuStorage;
import com.wwdz.ch.core.util.UUID;
import com.wwdz.ch.db.dao.ItemDao;
import com.wwdz.ch.db.dto.request.CoinRequestDto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.util.Arrays;
import java.util.Base64;
@SpringBootTest
@RunWith(SpringJUnit4ClassRunner.class)
public class ItemServiceImplTest {
@Autowired
ItemService itemService;
@Autowired
QiniuStorage qiniuStorage;
@Autowired
SynCoinJob synCoinJob;
@Autowired
ItemDao itemDao;
@Autowired
AdminGoodsService adminGoodsService;
@Test
public void list() {
adminGoodsService.list(null, null,1, 10, "create_time", "desc");
}
@Test
public void upload() throws Exception {
String imgBaseStr = "";
/* byte[] bytes = new BASE64Decoder().decodeBuffer(imgBaseStr.trim());
String file64 = Base64.encodeToString(bytes, 0);
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
*/ String keyName = CommConsts.UPLOAD_PRE_DIRECTORY + System.currentTimeMillis();
qiniuStorage.storeBase64Str(imgBaseStr, keyName);
//
/* File file = new File("/Users/xxdxxs/Downloads/tt.jpg");
InputStream inputStream1 = new FileInputStream(file);
String keyName = "test002" + System.currentTimeMillis() + ".jpg";
System.out.println("keyName = " + keyName);
qiniuStorage.store(inputStream1, file.length(), "image/jpg", keyName);*/
// String url = qiniuStorage.generateUrl(keyName);
// System.out.println("url = " + url);
}
@Test
public void uploadOfSize() throws Exception {
String imageUrl = "https://cdn.wanwudezhi.com/quanku/YjFzNEgwMWxMTG9mTUlxQ2hVWTZKUzE2ODUwMDQ0NDg=.jpg";
URL url = new URL(imageUrl);
InputStream inputStream = url.openStream();
String keyName = UUID.fastUUID().toString();
BufferedImage bufferedImage = ImageIO.read(inputStream);
keyName = keyName + "_" + bufferedImage.getWidth() + "x" + bufferedImage.getHeight()+ ".jpg";
InputStream fileStream = bufferedImageToInputStream(bufferedImage, MediaTypeEnum.IMAGE_JPG.getExt());
qiniuStorage.store(fileStream, 1, "image/jpeg", keyName);
String imageUrlofSize = qiniuStorage.generateUrl(keyName);
System.out.println("imageUrlofSize = " + imageUrlofSize);
}
private static InputStream bufferedImageToInputStream(BufferedImage image, String type) {
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
ImageIO.write(image, type, os);
return new ByteArrayInputStream(os.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Test
public void deleteUserItems(){
CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setIds(Arrays.asList(767377L,767378L,767379L));
itemDao.deleteUserItems(coinRequestDto);
}
@Test
public void setCoin() {
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment