当前位置: 首页 > news >正文

大学生校园活动策划书湖北企业网站优化排名

大学生校园活动策划书,湖北企业网站优化排名,广东省安全教育平台入口登录,有做网站设计吗Spring Data MongoDB是Spring Data项目中的项目#xff0c;它提供了Spring编程模型的扩展#xff0c;用于编写使用MongoDB作为数据库的应用程序。 要使用NoSQLUnit为Spring Data MongoDB应用程序编写测试#xff0c;除了考虑Spring Data MongoDB使用一个名为_class的特殊属… Spring Data MongoDB是Spring Data项目中的项目它提供了Spring编程模型的扩展用于编写使用MongoDB作为数据库的应用程序。 要使用NoSQLUnit为Spring Data MongoDB应用程序编写测试除了考虑Spring Data MongoDB使用一个名为_class的特殊属性来将类型信息存储在文档中之外您不需要做任何其他事情。 _class属性将顶级文档以及复杂类型中的每个值的标准类名存储在文档中。 类型映射 MappingMongoConverter用作默认类型映射实现但您可以使用TypeAlias或实现TypeInformationMapper接口自定义更多类型。 应用 Starfleet已要求我们开发一个应用程序用于将所有星际飞船乘员的日志存储到他们的系统中。 为了实现此要求我们将在持久层使用MongoDB数据库作为后端系统并使用Spring Data MongoDB 。 日志文档具有下一个json格式 日志文件示例 {_class : com.lordofthejars.nosqlunit.springdata.mongodb.log.Log ,_id : 1 ,owner : Captain ,stardate : {century : 4 ,season : 3 ,sequence : 125 ,day : 8} ,messages : [We have entered a spectacular binary star system in the Kavis Alpha sector on a most critical mission of astrophysical research. Our eminent guest, Dr. Paul Stubbs, will attempt to study the decay of neutronium expelled at relativistic speeds from a massive stellar explosion which will occur here in a matter of hours. ,Our computer core has clearly been tampered with and yet there is no sign of a breach of security on board. We have engines back and will attempt to complete our mission. But without a reliable computer, Dr. Stubbs experiment is in serious jeopardy.] } 该文档被建模为两个Java类一个用于整个文档另一个用于stardate部分。 星际约会 Document public class Stardate {private int century;private int season;private int sequence;private int day;public static final Stardate createStardate(int century, int season, int sequence, int day) {Stardate stardate new Stardate();stardate.setCentury(century);stardate.setSeason(season);stardate.setSequence(sequence);stardate.setDay(day);return stardate;}//Getters and Setters } 日志类别 Document public class Log {Idprivate int logId;private String owner;private Stardate stardate;private ListString messages new ArrayListString();//Getters and Setters } 除了模型类我们还需要DAO类来实现CRUD操作和spring应用程序上下文文件。 MongoLogManager类 Repository public class MongoLogManager implements LogManager {private MongoTemplate mongoTemplate;public void create(Log log) {this.mongoTemplate.insert(log);}public ListLog findAll() {return this.mongoTemplate.findAll(Log.class);}Autowiredpublic void setMongoTemplate(MongoTemplate mongoTemplate) {this.mongoTemplate mongoTemplate;}} 应用程序上下文文件 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsdcontext:component-scan base-packagecom.lordofthejars.nosqlunit.springdata.mongodb/context:annotation-config//beans 对于此示例我们使用MongoTemplate类访问MongoDB来创建一个不复杂的示例但是在更大的项目中我建议通过在管理器类上实现CrudRepository接口来使用Spring Data Repository方法。 测试中 如前所述除了正确使用class属性之外您无需执行任何其他特殊操作。 让我们看看通过为日志数据库播种_log集合来测试findAll方法的数据集。 所有日志文件 {log:[{_class : com.lordofthejars.nosqlunit.springdata.mongodb.log.Log ,_id : 1 ,owner : Captain ,stardate : {century : 4 ,season : 3 ,sequence : 125 ,day : 8} ,messages : [We have entered a spectacular binary star system in the Kavis Alpha sector on a most critical mission of astrophysical research. Our eminent guest, Dr. Paul Stubbs, will attempt to study the decay of neutronium expelled at relativistic speeds from a massive stellar explosion which will occur here in a matter of hours. ,Our computer core has clearly been tampered with and yet there is no sign of a breach of security on board. We have engines back and will attempt to complete our mission. But without a reliable computer, Dr. Stubbs experiment is in serious jeopardy.]},{_class : com.lordofthejars.nosqlunit.springdata.mongodb.log.Log ,_id : 2 ,owner : Captain ,stardate : {century : 4 ,season : 3 ,sequence : 152 ,day : 4} ,messages : [We are cautiously entering the Delta Rana star system three days after receiving a distress call from the Federation colony on its fourth planet. The garbled transmission reported the colony under attack from an unidentified spacecraft. Our mission is one of rescue and, if necessary, confrontation with a hostile force.]}... } 看到_class属性设置为Log类的全限定名。 下一步是配置MongoTemplate以执行测试。 LocalhostMongoAppConfig Configuration Profile(test) public class LocalhostMongoAppConfig {private static final String DATABASE_NAME logs;public Bean Mongo mongo() throws UnknownHostException, MongoException {Mongo mongo new Mongo(localhost);return mongo;}public Bean MongoTemplate mongoTemplate() throws UnknownHostException, MongoException {MongoTemplate mongoTemplate new MongoTemplate(mongo(), DATABASE_NAME);return mongoTemplate;}} 注意仅当测试配置文件处于活动状态时此MongoTemplate对象才会实例化。 现在我们可以编写JUnit测试用例 当海军上将想要阅读日志时 RunWith(SpringJUnit4ClassRunner.class) ContextConfiguration(locations classpath:com/lordofthejars/nosqlunit/springdata/mongodb/log/application-context-test.xml) ActiveProfiles(test) UsingDataSet(locations all-logs.json, loadStrategy LoadStrategyEnum.CLEAN_INSERT) public class WhenAlmiralWantsToReadLogs {ClassRulepublic static ManagedMongoDb managedMongoDb newManagedMongoDbRule().mongodPath(/Users/alexsotobueno/Applications/mongodb-osx-x86_64-2.0.5).build();Rulepublic MongoDbRule mongoDbRule newMongoDbRule().defaultManagedMongoDb(logs);Autowiredprivate LogManager logManager;Testpublic void all_entries_should_be_loaded() {ListLog allLogs logManager.findAll();assertThat(allLogs, hasSize(3));}} 在上一课中有一些要点要看 由于NoSQLUnit使用JUnit规则因此您可以自由使用RunWith(SpringJUnit4ClassRunner) 。 使用ActiveProfiles我们正在加载测试配置而不是生产配置。 您可以毫无问题地使用Autowired 之类的Spring注释。 结论 为无Spring Data MongoDB编写测试和使用它的应用程序之间没有太大区别。 仅记住正确定义_class属性。 参考在One Jar To Rule All All博客中我们的JCG合作伙伴 Alex Soto 使用NoSQLUnit测试了Spring Data MongoDB应用程序 。 翻译自: https://www.javacodegeeks.com/2013/01/testing-spring-data-mongodb-applications-with-nosqlunit.html
http://www.sadfv.cn/news/4157/

相关文章:

  • 销售网站开发网页版qq登录网址
  • 成都网站建设好多钱邯郸信息港最新招聘信息2023
  • 建筑之家宁波网站seo哪家好
  • 网站建设动画教程网站与个人网站
  • 涞源网站建设模板网站建设
  • 湖北省网站建设caddy搭建wordpress
  • 为什么后台编辑内容和网站上面显示的内容不一致百度海外视频网站建设
  • 汕头网站设计公司做网站卖东西赚钱么
  • 临沂兰山建设局网站如何看出网站是用wordpress搭建
  • 网站美工建设意见广州网站开发小程序
  • 建网站多少钱网站备案号显示红色
  • 深圳网站建设 外包合作拼多多网站的类型
  • 柳州企业网站开发公司apache搭建网站
  • 阳山网站建设深圳手机集团网站建设
  • 风景名胜区建设部网站哪些网站可以做翻译兼职
  • wordpress分类二级域名seo内部优化
  • 越秀公司网站建设东莞市传送机技术支持 网站建设
  • 做网站国内好的服务器做网站风险分析
  • 太原网站优化培训网站开发工程师课程
  • 营销型网站公司安康市出租车公司
  • 湖北随州市城乡建设官方网站义乌做网站的公司
  • 西安网站建设昆奇牛商网官网
  • 做网站公司融资多少钱网站维护和更新
  • 响应式网站网站建设wordpress 在线教学
  • 网站返回404是什么意思如何更改 网站 关键词
  • 免费广告设计网站wordpress 搜索引擎收录
  • iis7.5 网站打不开网站建设的中期检查表
  • 网站关键字被百度收录设计图网址
  • 家装网站建设公司本周的重大新闻
  • 写作网站投稿平台六安市紧急公告