@Test public final void testVitamDocumentCodec() { try { new VitamDocumentCodec<>(Document.class); fail("should failed"); } catch (final IllegalArgumentException e) { } final VitamDocumentCodec<PseudoClass> vitamDocumentCodec = new VitamDocumentCodec<>(PseudoClass.class); final PseudoClass document = new PseudoClass(); assertTrue(vitamDocumentCodec.documentHasId(document)); assertNotNull(vitamDocumentCodec.getDocumentId(document)); assertNotNull(vitamDocumentCodec.generateIdIfAbsentFromDocument(document)); assertEquals(PseudoClass.class, vitamDocumentCodec.getEncoderClass()); document.remove("_id"); assertFalse(vitamDocumentCodec.documentHasId(document)); try { vitamDocumentCodec.getDocumentId(document); fail("should failed"); } catch (final IllegalStateException e) { } assertNotNull(vitamDocumentCodec.generateIdIfAbsentFromDocument(document)); assertTrue(vitamDocumentCodec.documentHasId(document)); assertNotNull(vitamDocumentCodec.getDocumentId(document)); }
public VitamDocumentCodec(Class<T> clazz) { try { documentCodec = new DocumentCodec(); clasz = clazz; constructor = clazz.getConstructor(Document.class); } catch (final Exception ex) { throw new IllegalArgumentException(ex); } }
VitamDocumentCodec implements CollectibleCodec<T> { public VitamDocumentCodec(Class<T> clazz) { try { documentCodec = new DocumentCodec(); clasz = clazz; constructor = clazz.getConstructor(Document.class); } catch (final Exception ex) { throw new IllegalArgumentException(ex); } } }
VitamDocumentCodec implements CollectibleCodec<T> { public VitamDocumentCodec(Class<T> clazz) { try { documentCodec = new DocumentCodec(); clasz = clazz; constructor = clazz.getConstructor(Document.class); } catch (final Exception ex) { throw new IllegalArgumentException(ex); } } VitamDocumentCodec(Class<T> clazz); }
VitamDocumentCodec implements CollectibleCodec<T> { public VitamDocumentCodec(Class<T> clazz) { try { documentCodec = new DocumentCodec(); clasz = clazz; constructor = clazz.getConstructor(Document.class); } catch (final Exception ex) { throw new IllegalArgumentException(ex); } } VitamDocumentCodec(Class<T> clazz); @Override void encode(BsonWriter writer, T value, EncoderContext encoderContext); @Override T generateIdIfAbsentFromDocument(T document); @Override boolean documentHasId(T document); @Override BsonValue getDocumentId(T document); @Override Class<T> getEncoderClass(); @Override T decode(BsonReader reader, DecoderContext decoderContext); }
VitamDocumentCodec implements CollectibleCodec<T> { public VitamDocumentCodec(Class<T> clazz) { try { documentCodec = new DocumentCodec(); clasz = clazz; constructor = clazz.getConstructor(Document.class); } catch (final Exception ex) { throw new IllegalArgumentException(ex); } } VitamDocumentCodec(Class<T> clazz); @Override void encode(BsonWriter writer, T value, EncoderContext encoderContext); @Override T generateIdIfAbsentFromDocument(T document); @Override boolean documentHasId(T document); @Override BsonValue getDocumentId(T document); @Override Class<T> getEncoderClass(); @Override T decode(BsonReader reader, DecoderContext decoderContext);  }